847 changed files with 409731 additions and 0 deletions
@ -0,0 +1,46 @@ |
|||
package com.dreamchaser.depository_manage.aop; |
|||
|
|||
import org.aspectj.lang.JoinPoint; |
|||
import org.aspectj.lang.annotation.Aspect; |
|||
import org.aspectj.lang.annotation.Before; |
|||
import org.aspectj.lang.annotation.Pointcut; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.stereotype.Component; |
|||
import org.springframework.web.context.request.RequestAttributes; |
|||
import org.springframework.web.context.request.RequestContextHolder; |
|||
import org.springframework.web.context.request.ServletRequestAttributes; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import java.util.Arrays; |
|||
|
|||
/** |
|||
* 日志切面 |
|||
*/ |
|||
@Aspect |
|||
@Component |
|||
public class WebLogAspect { |
|||
private final Logger logger = LoggerFactory.getLogger(WebLogAspect.class); |
|||
|
|||
@Pointcut("execution(public * com.dreamchaser.depository_manage.controller..*.*(..))")//切入点描述 这个是controller包的切入点
|
|||
public void controllerLog(){}//签名,可以理解成这个切入点的一个名称
|
|||
|
|||
|
|||
public void logBeforeController(JoinPoint joinPoint) { |
|||
//这个RequestContextHolder是Springmvc提供来获得请求的东西
|
|||
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); |
|||
HttpServletRequest request = ((ServletRequestAttributes)requestAttributes).getRequest(); |
|||
|
|||
// 记录下请求内容
|
|||
logger.info("################URL : " + request.getRequestURL().toString()); |
|||
logger.info("################HTTP_METHOD : " + request.getMethod()); |
|||
logger.info("################IP : " + request.getRemoteAddr()); |
|||
logger.info("################THE ARGS OF THE CONTROLLER : " + Arrays.toString(joinPoint.getArgs())); |
|||
|
|||
//下面这个getSignature().getDeclaringTypeName()是获取包+类名的 然后后面的joinPoint.getSignature.getName()获取了方法名
|
|||
logger.info("################CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName()); |
|||
//logger.info("################TARGET: " + joinPoint.getTarget());//返回的是需要加强的目标类的对象
|
|||
//logger.info("################THIS: " + joinPoint.getThis());//返回的是经过加强后的代理类的对象
|
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
package com.dreamchaser.depository_manage.aop; |
|||
|
|||
import org.aspectj.lang.JoinPoint; |
|||
import org.aspectj.lang.annotation.Aspect; |
|||
import org.aspectj.lang.annotation.Before; |
|||
import org.aspectj.lang.annotation.Pointcut; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.stereotype.Component; |
|||
import org.springframework.web.context.request.RequestAttributes; |
|||
import org.springframework.web.context.request.RequestContextHolder; |
|||
import org.springframework.web.context.request.ServletRequestAttributes; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import java.util.Arrays; |
|||
|
|||
/** |
|||
* 日志切面 |
|||
*/ |
|||
@Aspect |
|||
@Component |
|||
public class WebLogAspect { |
|||
private final Logger logger = LoggerFactory.getLogger(WebLogAspect.class); |
|||
|
|||
@Pointcut("execution(public * com.dreamchaser.depository_manage.controller..*.*(..))")//切入点描述 这个是controller包的切入点
|
|||
public void controllerLog(){}//签名,可以理解成这个切入点的一个名称
|
|||
|
|||
|
|||
public void logBeforeController(JoinPoint joinPoint) { |
|||
//这个RequestContextHolder是Springmvc提供来获得请求的东西
|
|||
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); |
|||
HttpServletRequest request = ((ServletRequestAttributes)requestAttributes).getRequest(); |
|||
|
|||
// 记录下请求内容
|
|||
logger.info("################URL : " + request.getRequestURL().toString()); |
|||
logger.info("################HTTP_METHOD : " + request.getMethod()); |
|||
logger.info("################IP : " + request.getRemoteAddr()); |
|||
logger.info("################THE ARGS OF THE CONTROLLER : " + Arrays.toString(joinPoint.getArgs())); |
|||
|
|||
//下面这个getSignature().getDeclaringTypeName()是获取包+类名的 然后后面的joinPoint.getSignature.getName()获取了方法名
|
|||
logger.info("################CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName()); |
|||
//logger.info("################TARGET: " + joinPoint.getTarget());//返回的是需要加强的目标类的对象
|
|||
//logger.info("################THIS: " + joinPoint.getThis());//返回的是经过加强后的代理类的对象
|
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
# Default ignored files |
|||
/shelf/ |
|||
/workspace.xml |
|||
# Editor-based HTTP Client requests |
|||
/httpRequests/ |
|||
# Datasource local storage ignored files |
|||
/dataSources/ |
|||
/dataSources.local.xml |
|||
@ -0,0 +1,21 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project version="4"> |
|||
<component name="CompilerConfiguration"> |
|||
<annotationProcessing> |
|||
<profile default="true" name="Default" enabled="true" /> |
|||
<profile name="Maven default annotation processors profile" enabled="true"> |
|||
<sourceOutputDir name="target/generated-sources/annotations" /> |
|||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" /> |
|||
<outputRelativeToContentRoot value="true" /> |
|||
<module name="depository" /> |
|||
<module name="wms" /> |
|||
<module name="depositroy" /> |
|||
<module name="depository_manage (2)" /> |
|||
<module name="depository_manage" /> |
|||
</profile> |
|||
</annotationProcessing> |
|||
<bytecodeTargetLevel> |
|||
<module name="depository_manage (1)" target="1.5" /> |
|||
</bytecodeTargetLevel> |
|||
</component> |
|||
</project> |
|||
@ -0,0 +1,2 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<module type="JAVA_MODULE" version="4" /> |
|||
@ -0,0 +1,8 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project version="4"> |
|||
<component name="Encoding" native2AsciiForPropertiesFiles="true" defaultCharsetForPropertiesFiles="UTF-8"> |
|||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" /> |
|||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" /> |
|||
<file url="PROJECT" charset="UTF-8" /> |
|||
</component> |
|||
</project> |
|||
@ -0,0 +1,15 @@ |
|||
<component name="InspectionProjectProfileManager"> |
|||
<profile version="1.0"> |
|||
<option name="myName" value="Project Default" /> |
|||
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" /> |
|||
<inspection_tool class="SerializableHasSerialVersionUIDField" enabled="true" level="WARNING" enabled_by_default="true"> |
|||
<option name="ignoreAnonymousInnerClasses" value="false" /> |
|||
<option name="superClassString" value="java.awt.Component" /> |
|||
</inspection_tool> |
|||
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false"> |
|||
<option name="processCode" value="true" /> |
|||
<option name="processLiterals" value="true" /> |
|||
<option name="processComments" value="true" /> |
|||
</inspection_tool> |
|||
</profile> |
|||
</component> |
|||
@ -0,0 +1,25 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project version="4"> |
|||
<component name="RemoteRepositoriesConfiguration"> |
|||
<remote-repository> |
|||
<option name="id" value="spring-milestones" /> |
|||
<option name="name" value="Spring Milestones" /> |
|||
<option name="url" value="https://repo.spring.io/milestone" /> |
|||
</remote-repository> |
|||
<remote-repository> |
|||
<option name="id" value="central" /> |
|||
<option name="name" value="Central Repository" /> |
|||
<option name="url" value="https://repo.maven.apache.org/maven2" /> |
|||
</remote-repository> |
|||
<remote-repository> |
|||
<option name="id" value="central" /> |
|||
<option name="name" value="Maven Central repository" /> |
|||
<option name="url" value="https://repo1.maven.org/maven2" /> |
|||
</remote-repository> |
|||
<remote-repository> |
|||
<option name="id" value="jboss.community" /> |
|||
<option name="name" value="JBoss Community repository" /> |
|||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" /> |
|||
</remote-repository> |
|||
</component> |
|||
</project> |
|||
@ -0,0 +1,6 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project version="4"> |
|||
<component name="JavaScriptLibraryMappings"> |
|||
<file url="file://$PROJECT_DIR$" libraries="{index}" /> |
|||
</component> |
|||
</project> |
|||
@ -0,0 +1,22 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project version="4"> |
|||
<component name="ExternalStorageConfigurationManager" enabled="true" /> |
|||
<component name="FrameworkDetectionExcludesConfiguration"> |
|||
<file type="web" url="file://D:/Code/depository" /> |
|||
<file type="web" url="file://$PROJECT_DIR$" /> |
|||
</component> |
|||
<component name="JavaScriptSettings"> |
|||
<option name="languageLevel" value="ES6" /> |
|||
</component> |
|||
<component name="MavenProjectsManager"> |
|||
<option name="originalFiles"> |
|||
<list> |
|||
<option value="$PROJECT_DIR$/pom.xml" /> |
|||
</list> |
|||
</option> |
|||
</component> |
|||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8 (2)" project-jdk-type="JavaSDK" /> |
|||
<component name="ProjectType"> |
|||
<option name="id" value="jpab" /> |
|||
</component> |
|||
</project> |
|||
@ -0,0 +1,124 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project version="4"> |
|||
<component name="Palette2"> |
|||
<group name="Swing"> |
|||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
|||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" /> |
|||
</item> |
|||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
|||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" /> |
|||
</item> |
|||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
|||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" /> |
|||
</item> |
|||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true"> |
|||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" /> |
|||
</item> |
|||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
|||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" /> |
|||
<initial-values> |
|||
<property name="text" value="Button" /> |
|||
</initial-values> |
|||
</item> |
|||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
|||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> |
|||
<initial-values> |
|||
<property name="text" value="RadioButton" /> |
|||
</initial-values> |
|||
</item> |
|||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
|||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> |
|||
<initial-values> |
|||
<property name="text" value="CheckBox" /> |
|||
</initial-values> |
|||
</item> |
|||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
|||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" /> |
|||
<initial-values> |
|||
<property name="text" value="Label" /> |
|||
</initial-values> |
|||
</item> |
|||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
|||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> |
|||
<preferred-size width="150" height="-1" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
|||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> |
|||
<preferred-size width="150" height="-1" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
|||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> |
|||
<preferred-size width="150" height="-1" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
|||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> |
|||
<preferred-size width="150" height="50" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
|||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> |
|||
<preferred-size width="150" height="50" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
|||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> |
|||
<preferred-size width="150" height="50" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
|||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" /> |
|||
</item> |
|||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
|||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> |
|||
<preferred-size width="150" height="50" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
|||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3"> |
|||
<preferred-size width="150" height="50" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
|||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> |
|||
<preferred-size width="150" height="50" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
|||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> |
|||
<preferred-size width="200" height="200" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
|||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> |
|||
<preferred-size width="200" height="200" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
|||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> |
|||
</item> |
|||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
|||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> |
|||
</item> |
|||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
|||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" /> |
|||
</item> |
|||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
|||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" /> |
|||
</item> |
|||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
|||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1"> |
|||
<preferred-size width="-1" height="20" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
|||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" /> |
|||
</item> |
|||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
|||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" /> |
|||
</item> |
|||
</group> |
|||
</component> |
|||
</project> |
|||
@ -0,0 +1,6 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project version="4"> |
|||
<component name="VcsDirectoryMappings"> |
|||
<mapping directory="$PROJECT_DIR$" vcs="Git" /> |
|||
</component> |
|||
</project> |
|||
@ -0,0 +1,2 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<module type="JAVA_MODULE" version="4" /> |
|||
@ -0,0 +1,118 @@ |
|||
/* |
|||
* Copyright 2007-present the original author or authors. |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* https://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
|
|||
import java.net.*; |
|||
import java.io.*; |
|||
import java.nio.channels.*; |
|||
import java.util.Properties; |
|||
|
|||
public class MavenWrapperDownloader { |
|||
|
|||
private static final String WRAPPER_VERSION = "0.5.6"; |
|||
/** |
|||
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. |
|||
*/ |
|||
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" |
|||
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; |
|||
|
|||
/** |
|||
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to |
|||
* use instead of the default one. |
|||
*/ |
|||
private static final String MAVEN_WRAPPER_PROPERTIES_PATH = |
|||
".mvn/wrapper/maven-wrapper.properties"; |
|||
|
|||
/** |
|||
* Path where the maven-wrapper.jar will be saved to. |
|||
*/ |
|||
private static final String MAVEN_WRAPPER_JAR_PATH = |
|||
".mvn/wrapper/maven-wrapper.jar"; |
|||
|
|||
/** |
|||
* Name of the property which should be used to override the default download url for the wrapper. |
|||
*/ |
|||
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; |
|||
|
|||
public static void main(String args[]) { |
|||
System.out.println("- Downloader started"); |
|||
File baseDirectory = new File(args[0]); |
|||
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); |
|||
|
|||
// If the maven-wrapper.properties exists, read it and check if it contains a custom
|
|||
// wrapperUrl parameter.
|
|||
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); |
|||
String url = DEFAULT_DOWNLOAD_URL; |
|||
if (mavenWrapperPropertyFile.exists()) { |
|||
FileInputStream mavenWrapperPropertyFileInputStream = null; |
|||
try { |
|||
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); |
|||
Properties mavenWrapperProperties = new Properties(); |
|||
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); |
|||
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); |
|||
} catch (IOException e) { |
|||
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); |
|||
} finally { |
|||
try { |
|||
if (mavenWrapperPropertyFileInputStream != null) { |
|||
mavenWrapperPropertyFileInputStream.close(); |
|||
} |
|||
} catch (IOException e) { |
|||
// Ignore ...
|
|||
} |
|||
} |
|||
} |
|||
System.out.println("- Downloading from: " + url); |
|||
|
|||
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); |
|||
if (!outputFile.getParentFile().exists()) { |
|||
if (!outputFile.getParentFile().mkdirs()) { |
|||
System.out.println( |
|||
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); |
|||
} |
|||
} |
|||
System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); |
|||
try { |
|||
downloadFileFromURL(url, outputFile); |
|||
System.out.println("Done"); |
|||
System.exit(0); |
|||
} catch (Throwable e) { |
|||
System.out.println("- Error downloading"); |
|||
e.printStackTrace(); |
|||
System.exit(1); |
|||
} |
|||
} |
|||
|
|||
private static void downloadFileFromURL(String urlString, File destination) throws Exception { |
|||
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { |
|||
String username = System.getenv("MVNW_USERNAME"); |
|||
char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); |
|||
Authenticator.setDefault(new Authenticator() { |
|||
@Override |
|||
protected PasswordAuthentication getPasswordAuthentication() { |
|||
return new PasswordAuthentication(username, password); |
|||
} |
|||
}); |
|||
} |
|||
URL website = new URL(urlString); |
|||
ReadableByteChannel rbc; |
|||
rbc = Channels.newChannel(website.openStream()); |
|||
FileOutputStream fos = new FileOutputStream(destination); |
|||
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); |
|||
fos.close(); |
|||
rbc.close(); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,2 @@ |
|||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip |
|||
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar |
|||
@ -0,0 +1,6 @@ |
|||
{ |
|||
"ExpandedNodes": [ |
|||
"" |
|||
], |
|||
"PreviewInSolutionExplorer": false |
|||
} |
|||
Binary file not shown.
Binary file not shown.
@ -0,0 +1,310 @@ |
|||
#!/bin/sh |
|||
# ---------------------------------------------------------------------------- |
|||
# Licensed to the Apache Software Foundation (ASF) under one |
|||
# or more contributor license agreements. See the NOTICE file |
|||
# distributed with this work for additional information |
|||
# regarding copyright ownership. The ASF licenses this file |
|||
# to you under the Apache License, Version 2.0 (the |
|||
# "License"); you may not use this file except in compliance |
|||
# with the License. You may obtain a copy of the License at |
|||
# |
|||
# https://www.apache.org/licenses/LICENSE-2.0 |
|||
# |
|||
# Unless required by applicable law or agreed to in writing, |
|||
# software distributed under the License is distributed on an |
|||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
# KIND, either express or implied. See the License for the |
|||
# specific language governing permissions and limitations |
|||
# under the License. |
|||
# ---------------------------------------------------------------------------- |
|||
|
|||
# ---------------------------------------------------------------------------- |
|||
# Maven Start Up Batch script |
|||
# |
|||
# Required ENV vars: |
|||
# ------------------ |
|||
# JAVA_HOME - location of a JDK home dir |
|||
# |
|||
# Optional ENV vars |
|||
# ----------------- |
|||
# M2_HOME - location of maven2's installed home dir |
|||
# MAVEN_OPTS - parameters passed to the Java VM when running Maven |
|||
# e.g. to debug Maven itself, use |
|||
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 |
|||
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files |
|||
# ---------------------------------------------------------------------------- |
|||
|
|||
if [ -z "$MAVEN_SKIP_RC" ] ; then |
|||
|
|||
if [ -f /etc/mavenrc ] ; then |
|||
. /etc/mavenrc |
|||
fi |
|||
|
|||
if [ -f "$HOME/.mavenrc" ] ; then |
|||
. "$HOME/.mavenrc" |
|||
fi |
|||
|
|||
fi |
|||
|
|||
# OS specific support. $var _must_ be set to either true or false. |
|||
cygwin=false; |
|||
darwin=false; |
|||
mingw=false |
|||
case "`uname`" in |
|||
CYGWIN*) cygwin=true ;; |
|||
MINGW*) mingw=true;; |
|||
Darwin*) darwin=true |
|||
# Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home |
|||
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html |
|||
if [ -z "$JAVA_HOME" ]; then |
|||
if [ -x "/usr/libexec/java_home" ]; then |
|||
export JAVA_HOME="`/usr/libexec/java_home`" |
|||
else |
|||
export JAVA_HOME="/Library/Java/Home" |
|||
fi |
|||
fi |
|||
;; |
|||
esac |
|||
|
|||
if [ -z "$JAVA_HOME" ] ; then |
|||
if [ -r /etc/gentoo-release ] ; then |
|||
JAVA_HOME=`java-config --jre-home` |
|||
fi |
|||
fi |
|||
|
|||
if [ -z "$M2_HOME" ] ; then |
|||
## resolve links - $0 may be a link to maven's home |
|||
PRG="$0" |
|||
|
|||
# need this for relative symlinks |
|||
while [ -h "$PRG" ] ; do |
|||
ls=`ls -ld "$PRG"` |
|||
link=`expr "$ls" : '.*-> \(.*\)$'` |
|||
if expr "$link" : '/.*' > /dev/null; then |
|||
PRG="$link" |
|||
else |
|||
PRG="`dirname "$PRG"`/$link" |
|||
fi |
|||
done |
|||
|
|||
saveddir=`pwd` |
|||
|
|||
M2_HOME=`dirname "$PRG"`/.. |
|||
|
|||
# make it fully qualified |
|||
M2_HOME=`cd "$M2_HOME" && pwd` |
|||
|
|||
cd "$saveddir" |
|||
# echo Using m2 at $M2_HOME |
|||
fi |
|||
|
|||
# For Cygwin, ensure paths are in UNIX format before anything is touched |
|||
if $cygwin ; then |
|||
[ -n "$M2_HOME" ] && |
|||
M2_HOME=`cygpath --unix "$M2_HOME"` |
|||
[ -n "$JAVA_HOME" ] && |
|||
JAVA_HOME=`cygpath --unix "$JAVA_HOME"` |
|||
[ -n "$CLASSPATH" ] && |
|||
CLASSPATH=`cygpath --path --unix "$CLASSPATH"` |
|||
fi |
|||
|
|||
# For Mingw, ensure paths are in UNIX format before anything is touched |
|||
if $mingw ; then |
|||
[ -n "$M2_HOME" ] && |
|||
M2_HOME="`(cd "$M2_HOME"; pwd)`" |
|||
[ -n "$JAVA_HOME" ] && |
|||
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" |
|||
fi |
|||
|
|||
if [ -z "$JAVA_HOME" ]; then |
|||
javaExecutable="`which javac`" |
|||
if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then |
|||
# readlink(1) is not available as standard on Solaris 10. |
|||
readLink=`which readlink` |
|||
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then |
|||
if $darwin ; then |
|||
javaHome="`dirname \"$javaExecutable\"`" |
|||
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" |
|||
else |
|||
javaExecutable="`readlink -f \"$javaExecutable\"`" |
|||
fi |
|||
javaHome="`dirname \"$javaExecutable\"`" |
|||
javaHome=`expr "$javaHome" : '\(.*\)/bin'` |
|||
JAVA_HOME="$javaHome" |
|||
export JAVA_HOME |
|||
fi |
|||
fi |
|||
fi |
|||
|
|||
if [ -z "$JAVACMD" ] ; then |
|||
if [ -n "$JAVA_HOME" ] ; then |
|||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then |
|||
# IBM's JDK on AIX uses strange locations for the executables |
|||
JAVACMD="$JAVA_HOME/jre/sh/java" |
|||
else |
|||
JAVACMD="$JAVA_HOME/bin/java" |
|||
fi |
|||
else |
|||
JAVACMD="`which java`" |
|||
fi |
|||
fi |
|||
|
|||
if [ ! -x "$JAVACMD" ] ; then |
|||
echo "Error: JAVA_HOME is not defined correctly." >&2 |
|||
echo " We cannot execute $JAVACMD" >&2 |
|||
exit 1 |
|||
fi |
|||
|
|||
if [ -z "$JAVA_HOME" ] ; then |
|||
echo "Warning: JAVA_HOME environment variable is not set." |
|||
fi |
|||
|
|||
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher |
|||
|
|||
# traverses directory structure from process work directory to filesystem root |
|||
# first directory with .mvn subdirectory is considered project base directory |
|||
find_maven_basedir() { |
|||
|
|||
if [ -z "$1" ] |
|||
then |
|||
echo "Path not specified to find_maven_basedir" |
|||
return 1 |
|||
fi |
|||
|
|||
basedir="$1" |
|||
wdir="$1" |
|||
while [ "$wdir" != '/' ] ; do |
|||
if [ -d "$wdir"/.mvn ] ; then |
|||
basedir=$wdir |
|||
break |
|||
fi |
|||
# workaround for JBEAP-8937 (on Solaris 10/Sparc) |
|||
if [ -d "${wdir}" ]; then |
|||
wdir=`cd "$wdir/.."; pwd` |
|||
fi |
|||
# end of workaround |
|||
done |
|||
echo "${basedir}" |
|||
} |
|||
|
|||
# concatenates all lines of a file |
|||
concat_lines() { |
|||
if [ -f "$1" ]; then |
|||
echo "$(tr -s '\n' ' ' < "$1")" |
|||
fi |
|||
} |
|||
|
|||
BASE_DIR=`find_maven_basedir "$(pwd)"` |
|||
if [ -z "$BASE_DIR" ]; then |
|||
exit 1; |
|||
fi |
|||
|
|||
########################################################################################## |
|||
# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central |
|||
# This allows using the maven wrapper in projects that prohibit checking in binary data. |
|||
########################################################################################## |
|||
if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then |
|||
if [ "$MVNW_VERBOSE" = true ]; then |
|||
echo "Found .mvn/wrapper/maven-wrapper.jar" |
|||
fi |
|||
else |
|||
if [ "$MVNW_VERBOSE" = true ]; then |
|||
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." |
|||
fi |
|||
if [ -n "$MVNW_REPOURL" ]; then |
|||
jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" |
|||
else |
|||
jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" |
|||
fi |
|||
while IFS="=" read key value; do |
|||
case "$key" in (wrapperUrl) jarUrl="$value"; break ;; |
|||
esac |
|||
done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" |
|||
if [ "$MVNW_VERBOSE" = true ]; then |
|||
echo "Downloading from: $jarUrl" |
|||
fi |
|||
wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" |
|||
if $cygwin; then |
|||
wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` |
|||
fi |
|||
|
|||
if command -v wget > /dev/null; then |
|||
if [ "$MVNW_VERBOSE" = true ]; then |
|||
echo "Found wget ... using wget" |
|||
fi |
|||
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then |
|||
wget "$jarUrl" -O "$wrapperJarPath" |
|||
else |
|||
wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" |
|||
fi |
|||
elif command -v curl > /dev/null; then |
|||
if [ "$MVNW_VERBOSE" = true ]; then |
|||
echo "Found curl ... using curl" |
|||
fi |
|||
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then |
|||
curl -o "$wrapperJarPath" "$jarUrl" -f |
|||
else |
|||
curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f |
|||
fi |
|||
|
|||
else |
|||
if [ "$MVNW_VERBOSE" = true ]; then |
|||
echo "Falling back to using Java to download" |
|||
fi |
|||
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" |
|||
# For Cygwin, switch paths to Windows format before running javac |
|||
if $cygwin; then |
|||
javaClass=`cygpath --path --windows "$javaClass"` |
|||
fi |
|||
if [ -e "$javaClass" ]; then |
|||
if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then |
|||
if [ "$MVNW_VERBOSE" = true ]; then |
|||
echo " - Compiling MavenWrapperDownloader.java ..." |
|||
fi |
|||
# Compiling the Java class |
|||
("$JAVA_HOME/bin/javac" "$javaClass") |
|||
fi |
|||
if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then |
|||
# Running the downloader |
|||
if [ "$MVNW_VERBOSE" = true ]; then |
|||
echo " - Running MavenWrapperDownloader.java ..." |
|||
fi |
|||
("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") |
|||
fi |
|||
fi |
|||
fi |
|||
fi |
|||
########################################################################################## |
|||
# End of extension |
|||
########################################################################################## |
|||
|
|||
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} |
|||
if [ "$MVNW_VERBOSE" = true ]; then |
|||
echo $MAVEN_PROJECTBASEDIR |
|||
fi |
|||
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" |
|||
|
|||
# For Cygwin, switch paths to Windows format before running java |
|||
if $cygwin; then |
|||
[ -n "$M2_HOME" ] && |
|||
M2_HOME=`cygpath --path --windows "$M2_HOME"` |
|||
[ -n "$JAVA_HOME" ] && |
|||
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` |
|||
[ -n "$CLASSPATH" ] && |
|||
CLASSPATH=`cygpath --path --windows "$CLASSPATH"` |
|||
[ -n "$MAVEN_PROJECTBASEDIR" ] && |
|||
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` |
|||
fi |
|||
|
|||
# Provide a "standardized" way to retrieve the CLI args that will |
|||
# work with both Windows and non-Windows executions. |
|||
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" |
|||
export MAVEN_CMD_LINE_ARGS |
|||
|
|||
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain |
|||
|
|||
exec "$JAVACMD" \ |
|||
$MAVEN_OPTS \ |
|||
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ |
|||
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ |
|||
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" |
|||
@ -0,0 +1,182 @@ |
|||
@REM ---------------------------------------------------------------------------- |
|||
@REM Licensed to the Apache Software Foundation (ASF) under one |
|||
@REM or more contributor license agreements. See the NOTICE file |
|||
@REM distributed with this work for additional information |
|||
@REM regarding copyright ownership. The ASF licenses this file |
|||
@REM to you under the Apache License, Version 2.0 (the |
|||
@REM "License"); you may not use this file except in compliance |
|||
@REM with the License. You may obtain a copy of the License at |
|||
@REM |
|||
@REM https://www.apache.org/licenses/LICENSE-2.0 |
|||
@REM |
|||
@REM Unless required by applicable law or agreed to in writing, |
|||
@REM software distributed under the License is distributed on an |
|||
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
@REM KIND, either express or implied. See the License for the |
|||
@REM specific language governing permissions and limitations |
|||
@REM under the License. |
|||
@REM ---------------------------------------------------------------------------- |
|||
|
|||
@REM ---------------------------------------------------------------------------- |
|||
@REM Maven Start Up Batch script |
|||
@REM |
|||
@REM Required ENV vars: |
|||
@REM JAVA_HOME - location of a JDK home dir |
|||
@REM |
|||
@REM Optional ENV vars |
|||
@REM M2_HOME - location of maven2's installed home dir |
|||
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands |
|||
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending |
|||
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven |
|||
@REM e.g. to debug Maven itself, use |
|||
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 |
|||
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files |
|||
@REM ---------------------------------------------------------------------------- |
|||
|
|||
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' |
|||
@echo off |
|||
@REM set title of command window |
|||
title %0 |
|||
@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' |
|||
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% |
|||
|
|||
@REM set %HOME% to equivalent of $HOME |
|||
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") |
|||
|
|||
@REM Execute a user defined script before this one |
|||
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre |
|||
@REM check for pre script, once with legacy .bat ending and once with .cmd ending |
|||
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" |
|||
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" |
|||
:skipRcPre |
|||
|
|||
@setlocal |
|||
|
|||
set ERROR_CODE=0 |
|||
|
|||
@REM To isolate internal variables from possible post scripts, we use another setlocal |
|||
@setlocal |
|||
|
|||
@REM ==== START VALIDATION ==== |
|||
if not "%JAVA_HOME%" == "" goto OkJHome |
|||
|
|||
echo. |
|||
echo Error: JAVA_HOME not found in your environment. >&2 |
|||
echo Please set the JAVA_HOME variable in your environment to match the >&2 |
|||
echo location of your Java installation. >&2 |
|||
echo. |
|||
goto error |
|||
|
|||
:OkJHome |
|||
if exist "%JAVA_HOME%\bin\java.exe" goto init |
|||
|
|||
echo. |
|||
echo Error: JAVA_HOME is set to an invalid directory. >&2 |
|||
echo JAVA_HOME = "%JAVA_HOME%" >&2 |
|||
echo Please set the JAVA_HOME variable in your environment to match the >&2 |
|||
echo location of your Java installation. >&2 |
|||
echo. |
|||
goto error |
|||
|
|||
@REM ==== END VALIDATION ==== |
|||
|
|||
:init |
|||
|
|||
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". |
|||
@REM Fallback to current working directory if not found. |
|||
|
|||
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% |
|||
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir |
|||
|
|||
set EXEC_DIR=%CD% |
|||
set WDIR=%EXEC_DIR% |
|||
:findBaseDir |
|||
IF EXIST "%WDIR%"\.mvn goto baseDirFound |
|||
cd .. |
|||
IF "%WDIR%"=="%CD%" goto baseDirNotFound |
|||
set WDIR=%CD% |
|||
goto findBaseDir |
|||
|
|||
:baseDirFound |
|||
set MAVEN_PROJECTBASEDIR=%WDIR% |
|||
cd "%EXEC_DIR%" |
|||
goto endDetectBaseDir |
|||
|
|||
:baseDirNotFound |
|||
set MAVEN_PROJECTBASEDIR=%EXEC_DIR% |
|||
cd "%EXEC_DIR%" |
|||
|
|||
:endDetectBaseDir |
|||
|
|||
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig |
|||
|
|||
@setlocal EnableExtensions EnableDelayedExpansion |
|||
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a |
|||
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% |
|||
|
|||
:endReadAdditionalConfig |
|||
|
|||
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" |
|||
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" |
|||
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain |
|||
|
|||
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" |
|||
|
|||
FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( |
|||
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B |
|||
) |
|||
|
|||
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central |
|||
@REM This allows using the maven wrapper in projects that prohibit checking in binary data. |
|||
if exist %WRAPPER_JAR% ( |
|||
if "%MVNW_VERBOSE%" == "true" ( |
|||
echo Found %WRAPPER_JAR% |
|||
) |
|||
) else ( |
|||
if not "%MVNW_REPOURL%" == "" ( |
|||
SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" |
|||
) |
|||
if "%MVNW_VERBOSE%" == "true" ( |
|||
echo Couldn't find %WRAPPER_JAR%, downloading it ... |
|||
echo Downloading from: %DOWNLOAD_URL% |
|||
) |
|||
|
|||
powershell -Command "&{"^ |
|||
"$webclient = new-object System.Net.WebClient;"^ |
|||
"if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ |
|||
"$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ |
|||
"}"^ |
|||
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ |
|||
"}" |
|||
if "%MVNW_VERBOSE%" == "true" ( |
|||
echo Finished downloading %WRAPPER_JAR% |
|||
) |
|||
) |
|||
@REM End of extension |
|||
|
|||
@REM Provide a "standardized" way to retrieve the CLI args that will |
|||
@REM work with both Windows and non-Windows executions. |
|||
set MAVEN_CMD_LINE_ARGS=%* |
|||
|
|||
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* |
|||
if ERRORLEVEL 1 goto error |
|||
goto end |
|||
|
|||
:error |
|||
set ERROR_CODE=1 |
|||
|
|||
:end |
|||
@endlocal & set ERROR_CODE=%ERROR_CODE% |
|||
|
|||
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost |
|||
@REM check for post script, once with legacy .bat ending and once with .cmd ending |
|||
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" |
|||
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" |
|||
:skipRcPost |
|||
|
|||
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' |
|||
if "%MAVEN_BATCH_PAUSE%" == "on" pause |
|||
|
|||
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% |
|||
|
|||
exit /B %ERROR_CODE% |
|||
@ -0,0 +1,6 @@ |
|||
{ |
|||
"name": "depositroy", |
|||
"version": "1.0.0", |
|||
"dependencies": { |
|||
} |
|||
} |
|||
@ -0,0 +1,344 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|||
<modelVersion>4.0.0</modelVersion> |
|||
<groupId>com.dreamchaser</groupId> |
|||
<artifactId>depository_manage</artifactId> |
|||
<version>0.0.1-SNAPSHOT</version> |
|||
<name>depository_manage</name> |
|||
<description>work</description> |
|||
<packaging>war</packaging> |
|||
|
|||
<properties> |
|||
<java.version>1.8</java.version> |
|||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
|||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> |
|||
<spring-boot.version>2.3.7.RELEASE</spring-boot.version> |
|||
|
|||
<failOnMissingWebXml>false</failOnMissingWebXml> |
|||
</properties> |
|||
<dependencies> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-thymeleaf</artifactId> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-tomcat</artifactId> |
|||
<!--2023.08.29项目突然启动不了解决方案start--> |
|||
<!-- compile<scope>provided</scope>provided--> |
|||
<scope>provided</scope> |
|||
<!--2023.08.29项目突然启动不了解决方案end--> |
|||
|
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-websocket</artifactId> |
|||
</dependency> |
|||
|
|||
|
|||
<!-- <!–跨域工具包–>--> |
|||
<!-- <dependency>--> |
|||
<!-- <groupId>com.thetransactioncompany</groupId>--> |
|||
<!-- <artifactId>cors-filter</artifactId>--> |
|||
<!-- </dependency>--> |
|||
<!--发送邮箱依赖--> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-mail</artifactId> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.baomidou</groupId> |
|||
<artifactId>mybatis-plus-boot-starter</artifactId> |
|||
<version>3.4.2</version> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>com.baomidou</groupId> |
|||
<artifactId>dynamic-datasource-spring-boot-starter</artifactId> |
|||
<version>3.2.0</version> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>log4j</groupId> |
|||
<artifactId>log4j</artifactId> |
|||
<version>1.2.14</version> |
|||
<scope>compile</scope> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>ch.qos.logback</groupId> |
|||
<artifactId>logback-classic</artifactId> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>mysql</groupId> |
|||
<artifactId>mysql-connector-java</artifactId> |
|||
<scope>runtime</scope> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.alibaba</groupId> |
|||
<artifactId>druid-spring-boot-starter</artifactId> |
|||
<version>1.2.6</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.projectlombok</groupId> |
|||
<artifactId>lombok</artifactId> |
|||
<optional>true</optional> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-web</artifactId> |
|||
<exclusions> |
|||
<exclusion> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-tomcat</artifactId> |
|||
</exclusion> |
|||
</exclusions> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-test</artifactId> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-configuration-processor</artifactId> |
|||
<optional>true</optional> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>joda-time</groupId> |
|||
<artifactId>joda-time</artifactId> |
|||
<version>2.9.7</version> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>javax.servlet</groupId> |
|||
<artifactId>javax.servlet-api</artifactId> |
|||
<version>3.1.0</version> |
|||
<scope>provided</scope> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>com.belerweb</groupId> |
|||
<artifactId>pinyin4j</artifactId> |
|||
<version>2.5.1</version> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>junit</groupId> |
|||
<artifactId>junit</artifactId> |
|||
<scope>test</scope> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.aspectj</groupId> |
|||
<artifactId>aspectjweaver</artifactId> |
|||
<version>1.9.5</version> |
|||
</dependency> |
|||
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson --> |
|||
<dependency> |
|||
<groupId>com.alibaba</groupId> |
|||
<artifactId>fastjson</artifactId> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-devtools</artifactId> |
|||
<optional>true</optional> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.alibaba</groupId> |
|||
<artifactId>fastjson</artifactId> |
|||
<version>1.2.62</version> |
|||
</dependency> |
|||
|
|||
<!-- 用于实现excel表的导入导出--> |
|||
<dependency> |
|||
<groupId>com.alibaba</groupId> |
|||
<artifactId>easyexcel</artifactId> |
|||
<version>3.1.0</version> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>commons-lang</groupId> |
|||
<artifactId>commons-lang</artifactId> |
|||
<version>2.5</version> |
|||
</dependency> |
|||
|
|||
<!-- 用于处理csv文件解析--> |
|||
<dependency> |
|||
<groupId>cn.hutool</groupId> |
|||
<artifactId>hutool-all</artifactId> |
|||
<version>5.6.7</version> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>org.apache.httpcomponents</groupId> |
|||
<artifactId>httpclient</artifactId> |
|||
<version>4.5</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.apache.httpcomponents</groupId> |
|||
<artifactId>httpmime</artifactId> |
|||
<version>4.5</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.apache.httpcomponents</groupId> |
|||
<artifactId>httpcore</artifactId> |
|||
<version>4.4.1</version> |
|||
</dependency> |
|||
|
|||
|
|||
|
|||
<!-- 用于redis的连接--> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-data-redis</artifactId> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.apache.commons</groupId> |
|||
<artifactId>commons-pool2</artifactId> |
|||
<version>2.6.0</version> |
|||
</dependency> |
|||
|
|||
<!-- 用于redisson分布锁--> |
|||
<dependency> |
|||
<groupId>org.redisson</groupId> |
|||
<artifactId>redisson</artifactId> |
|||
<version>3.8.2</version> |
|||
<optional>true</optional> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.redisson</groupId> |
|||
<artifactId>redisson-spring-boot-starter</artifactId> |
|||
<version>3.8.2</version> |
|||
</dependency> |
|||
|
|||
<!-- 用于生成二维码依赖--> |
|||
<dependency> |
|||
<groupId>com.google.zxing</groupId> |
|||
<artifactId>javase</artifactId> |
|||
<version>3.4.0</version> |
|||
</dependency> |
|||
|
|||
<!-- 用于检测访问设备类型--> |
|||
<!-- https://mvnrepository.com/artifact/org.springframework.mobile/spring-mobile-device --> |
|||
<dependency> |
|||
<groupId>org.springframework.mobile</groupId> |
|||
<artifactId>spring-mobile-device</artifactId> |
|||
<version>1.1.5.RELEASE</version> |
|||
</dependency> |
|||
|
|||
|
|||
<dependency> |
|||
<groupId>org.dom4j</groupId> |
|||
<artifactId>dom4j</artifactId> |
|||
<version>2.0.0</version> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>com.fasterxml.jackson.dataformat</groupId> |
|||
<artifactId>jackson-dataformat-xml</artifactId> |
|||
<version>2.8.8</version> |
|||
</dependency> |
|||
|
|||
|
|||
<!-- https://mvnrepository.com/artifact/net.java.dev.jna/jna --> |
|||
<dependency> |
|||
<groupId>net.java.dev.jna</groupId> |
|||
<artifactId>jna</artifactId> |
|||
<version>5.5.0</version> |
|||
</dependency> |
|||
|
|||
<!--用于执行 WMI 查询的 Java API,为了获取端口--> |
|||
<dependency> |
|||
<groupId>com.profesorfalken</groupId> |
|||
<artifactId>WMI4Java</artifactId> |
|||
<version>1.6.3</version> |
|||
</dependency> |
|||
|
|||
<!-- https://mvnrepository.com/artifact/commons-codec/commons-codec --> |
|||
<dependency> |
|||
<groupId>commons-codec</groupId> |
|||
<artifactId>commons-codec</artifactId> |
|||
<version>1.13</version> |
|||
</dependency> |
|||
|
|||
|
|||
</dependencies> |
|||
|
|||
<repositories> |
|||
<repository> |
|||
<id>spring-milestones</id> |
|||
<name>Spring Milestones</name> |
|||
<url>https://repo.spring.io/milestone</url> |
|||
</repository> |
|||
</repositories> |
|||
|
|||
|
|||
<dependencyManagement> |
|||
<dependencies> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-dependencies</artifactId> |
|||
<version>${spring-boot.version}</version> |
|||
<type>pom</type> |
|||
<scope>import</scope> |
|||
</dependency> |
|||
</dependencies> |
|||
</dependencyManagement> |
|||
|
|||
<build> |
|||
<finalName>depository</finalName> |
|||
<plugins> |
|||
<plugin> |
|||
<groupId>org.apache.maven.plugins</groupId> |
|||
<artifactId>maven-compiler-plugin</artifactId> |
|||
<version>3.8.1</version> |
|||
<configuration> |
|||
<source>1.8</source> |
|||
<target>1.8</target> |
|||
<encoding>UTF-8</encoding> |
|||
</configuration> |
|||
</plugin> |
|||
<plugin> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-maven-plugin</artifactId> |
|||
<version>2.3.7.RELEASE</version> |
|||
<configuration> |
|||
<mainClass>com.dreamchaser.depository_manage.DepositoryManageApplication</mainClass> |
|||
<!--热部署liwx 20230804--> |
|||
<!--<fork>true</fork>--> |
|||
</configuration> |
|||
<executions> |
|||
<execution> |
|||
<id>repackage</id> |
|||
<goals> |
|||
<goal>repackage</goal> |
|||
</goals> |
|||
</execution> |
|||
</executions> |
|||
</plugin> |
|||
<!-- war 插件 --> |
|||
<plugin> |
|||
<groupId>org.apache.maven.plugins</groupId> |
|||
<artifactId>maven-war-plugin</artifactId> |
|||
<configuration> |
|||
<warName>depository</warName> |
|||
</configuration> |
|||
</plugin> |
|||
</plugins> |
|||
<resources> |
|||
<resource> |
|||
<directory>src/main/java</directory> |
|||
<includes> |
|||
<include>**/*.xml</include> |
|||
</includes> |
|||
</resource> |
|||
<resource> |
|||
<directory>src/main/resources</directory> |
|||
<includes> |
|||
<include>**/*.*</include> |
|||
</includes> |
|||
</resource> |
|||
</resources> |
|||
</build> |
|||
|
|||
</project> |
|||
@ -0,0 +1,24 @@ |
|||
package com.dreamchaser.depository_manage; |
|||
|
|||
import com.alibaba.druid.pool.xa.DruidXADataSource; |
|||
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure; |
|||
import org.springframework.boot.SpringApplication; |
|||
import org.springframework.boot.autoconfigure.SpringBootApplication; |
|||
import org.springframework.boot.builder.SpringApplicationBuilder; |
|||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; |
|||
import org.springframework.transaction.annotation.EnableTransactionManagement; |
|||
|
|||
@EnableTransactionManagement |
|||
@SpringBootApplication(exclude = DruidDataSourceAutoConfigure.class) |
|||
public class DepositoryManageApplication extends SpringBootServletInitializer { |
|||
|
|||
public static void main(String[] args) { |
|||
SpringApplication.run(DepositoryManageApplication.class, args); |
|||
} |
|||
|
|||
@Override |
|||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { |
|||
return application.sources(DepositoryManageApplication.class); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
package com.dreamchaser.depository_manage.EPSON.ENS; |
|||
|
|||
import com.sun.jna.Memory; |
|||
import com.sun.jna.Pointer; |
|||
|
|||
public class ENS { |
|||
|
|||
protected Pointer _ptrToStruct = new Memory(10); |
|||
private boolean _disposed = false; |
|||
} |
|||
@ -0,0 +1,341 @@ |
|||
package com.dreamchaser.depository_manage.EPSON.ENS; |
|||
|
|||
import sun.management.snmp.jvmmib.EnumJvmMemPoolThreshdSupport; |
|||
|
|||
/** |
|||
* 用于ENS相关的枚举类 |
|||
*/ |
|||
public class ENSEnumrations { |
|||
|
|||
|
|||
/** |
|||
* 用于ENS错误码的枚举 |
|||
*/ |
|||
public enum ENSErrorCode |
|||
{ |
|||
ERR_BASE (0), |
|||
ERR_PARAMETER (ERR_BASE.getI()- 1), //Values of necessary arguments have not been set.
|
|||
ERR_INITIALIZE (ERR_BASE.getI()- 2), //Failure in initialization of bi-directional communication module.
|
|||
//Or API has not been initialized.
|
|||
ERR_NOTSUPPORT (ERR_BASE.getI()- 3), //Error before the start of communication (i.e. a port specification error etc.).
|
|||
//Or other error occurred in bi-directional communication module.
|
|||
ERR_PRINTER (ERR_BASE.getI()- 4), //Printer has not been registered
|
|||
ERR_NOTFOUND (ERR_BASE.getI()- 5), //Communication cannot be opened.
|
|||
//Communication trouble. Or there is no device information which can be acquired.
|
|||
ERR_BUFFERSIZE (ERR_BASE.getI()- 6), //Specified buffer size value is too small.
|
|||
ERR_TEMPORARY (ERR_BASE.getI()- 7), //Temporary storage memory used in API cannot be secured.
|
|||
ERR_COMMUNICATION (ERR_BASE.getI()- 8), //Communication error occurred inside system of bi-directional communication module.
|
|||
ERR_INVALIDDATA (ERR_BASE.getI()- 9), //Data acquired by API contains invalid code, so data is not reliable.
|
|||
ERR_CHANNEL (ERR_BASE.getI()- 10), //No usable communication channel for packet transmission/reception.
|
|||
ERR_HANDLE (ERR_BASE.getI()- 11), //Handle of specified bi-directional communication module is invalid.
|
|||
ERR_BUSY (ERR_BASE.getI()- 12), //Port could not be opened while printer is printing (communicating).
|
|||
ERR_LOADDLL (ERR_BASE.getI()- 13), //Failure in loading bi-directional communication module.
|
|||
ERR_DEVICEID (ERR_BASE.getI()- 14), //Specified DeviceID information is invalid.
|
|||
ERR_PRNHANDLE (ERR_BASE.getI()- 15), //Specified printer handle is invalid.
|
|||
ERR_PORT (ERR_BASE.getI()- 16), //Unsupported printer path name was specified.
|
|||
ERR_TIMEOUT (ERR_BASE.getI()- 17), //Receive processing stopped due to a time out.
|
|||
ERR_JOB1 (ERR_BASE.getI()- 18), //Job management error No. 1.
|
|||
ERR_JOB2 (ERR_BASE.getI()- 19), //Job management error No. 2.
|
|||
ERR_JOB3 (ERR_BASE.getI()- 20), //Job management error No. 3.
|
|||
ERR_INVALIDHANDLE ( ERR_BASE.getI()- 21),//Specified discovery handle is invalid.
|
|||
ERR_USERCANCEL (ERR_BASE.getI()- 22), //Discovery was canceled by user.
|
|||
ERR_THREADSTART (ERR_BASE.getI()- 23), //Failed in starting thread.
|
|||
ERR_TRAPRESOURCE ( ERR_BASE.getI()- 24), //Insufficient trap resource.
|
|||
ERR_SERVICE ( ERR_BASE.getI()- 25), //Core service error.
|
|||
ERR_JOBNOTSUPPORT ( ERR_BASE.getI()- 26),//Job management function is not supported.
|
|||
ERR_TRAPNOTSUPPORT ( ERR_BASE.getI()- 27), //Trap function is not supported.
|
|||
ERR_SETTRAP ( ERR_BASE.getI()- 28), //Trap setting failure.
|
|||
ERR_NOTRAPDATA ( ERR_BASE.getI()- 29), //No Trap notification data.
|
|||
ERR_GSTNOTSUPPORT ( ERR_BASE.getI()- 30),//Unsupported general status.
|
|||
ERR_OTHER ( - 31); //Other error;
|
|||
|
|||
private int i; |
|||
ENSErrorCode(int i) { |
|||
this.i = i; |
|||
} |
|||
public int getI() { |
|||
return i; |
|||
} |
|||
|
|||
/** |
|||
* 用于获取对应的枚举值 |
|||
* @return |
|||
*/ |
|||
public static ENSErrorCode getENSErrorCode(int i){ |
|||
switch (i) { |
|||
case 0: |
|||
return ERR_PARAMETER; |
|||
case -1: |
|||
return ERR_PARAMETER; |
|||
case -2: |
|||
return ERR_INITIALIZE; |
|||
case -3: |
|||
return ERR_NOTSUPPORT; |
|||
case -4: |
|||
return ERR_PRINTER; |
|||
case -5: |
|||
return ERR_NOTFOUND; |
|||
case -6: |
|||
return ERR_BUFFERSIZE; |
|||
case -7: |
|||
return ERR_TEMPORARY; |
|||
case -8: |
|||
return ERR_COMMUNICATION; |
|||
case -9: |
|||
return ERR_INVALIDDATA; |
|||
case -10: |
|||
return ERR_CHANNEL; |
|||
case -11: |
|||
return ERR_HANDLE; |
|||
case -12: |
|||
return ERR_BUSY; |
|||
case -13: |
|||
return ERR_LOADDLL; |
|||
case -14: |
|||
return ERR_DEVICEID; |
|||
case -15: |
|||
return ERR_PRNHANDLE; |
|||
case -16: |
|||
return ERR_PORT; |
|||
case -17: |
|||
return ERR_TIMEOUT; |
|||
case -18: |
|||
return ERR_JOB1; |
|||
case -19: |
|||
return ERR_JOB2; |
|||
case -20: |
|||
return ERR_JOB3; |
|||
case -21: |
|||
return ERR_INVALIDHANDLE; |
|||
case -22: |
|||
return ERR_USERCANCEL; |
|||
case -23: |
|||
return ERR_THREADSTART; |
|||
case -24: |
|||
return ERR_TRAPRESOURCE; |
|||
case -25: |
|||
return ERR_SERVICE; |
|||
case -26: |
|||
return ERR_JOBNOTSUPPORT; |
|||
case -27: |
|||
return ERR_TRAPNOTSUPPORT; |
|||
case -28: |
|||
return ERR_SETTRAP; |
|||
case -29: |
|||
return ERR_NOTRAPDATA; |
|||
case -30: |
|||
return ERR_GSTNOTSUPPORT; |
|||
case -31: |
|||
return ERR_OTHER; |
|||
default: |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
} |
|||
|
|||
/** |
|||
* 用于ENS类型的枚举 |
|||
*/ |
|||
public enum ENSType //Printer path type
|
|||
{ |
|||
TYPE_PORT (0), //Port
|
|||
TYPE_PRINTER (1), //Printer registration name
|
|||
TYPE_IPX (2); //IPX
|
|||
|
|||
|
|||
private int i; |
|||
ENSType(int i) { |
|||
|
|||
this.i = i; |
|||
} |
|||
public int getI() { |
|||
return i; |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于ENS路径类型的枚举 |
|||
*/ |
|||
public enum ENSPathType |
|||
{ |
|||
TYPE_EJL (0), //Printer compatible with EJL commands (Page printer)
|
|||
TYPE_REMOTE (1), //Printer compatible with remote commands (INK/SIDM printer)
|
|||
TYPE_UNKNOWN (100); //Type cannot be determined.
|
|||
|
|||
private int i; |
|||
|
|||
ENSPathType(int i) { |
|||
this.i = i; |
|||
} |
|||
|
|||
public int getI() { |
|||
return i; |
|||
} |
|||
|
|||
/** |
|||
* 用于获取对应的枚举值 |
|||
* @param i |
|||
* @return |
|||
*/ |
|||
public static ENSPathType getENSPathType(int i){ |
|||
switch (i){ |
|||
case 0: |
|||
return TYPE_EJL; |
|||
case 1: |
|||
return TYPE_REMOTE; |
|||
case 100: |
|||
return TYPE_UNKNOWN; |
|||
default: |
|||
return null; |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
//------------------------------------
|
|||
//Definitions Printer StateCode for TM-C3400/TM-C3500/TM-C7500 (printer type).
|
|||
//Please add StatusCode which are not being defined.
|
|||
//Some value that is not being defined in enum by specification change of SDK may be returned.
|
|||
//Refer SDK specifications for the latest definition.
|
|||
//------------------------------------
|
|||
public enum StatusCode |
|||
{ |
|||
ST_Error (0x00 ), |
|||
ST_TestPrint (0x01 ), |
|||
ST_Busy (0x02 ), |
|||
ST_Wait (0x03 ), |
|||
ST_Idle (0x04 ), |
|||
ST_NotPrint (0x05 ), |
|||
ST_Inkdrying (0x06 ), |
|||
ST_Cleaning (0x07 ); |
|||
|
|||
private int i; |
|||
StatusCode(int i) { |
|||
this.i = i; |
|||
} |
|||
|
|||
public int getI() { |
|||
return i; |
|||
} |
|||
|
|||
/** |
|||
* 用于获取对应的枚举值 |
|||
* @param i |
|||
* @return |
|||
*/ |
|||
public static StatusCode getStatusCode(int i){ |
|||
switch (i){ |
|||
case 0x00: |
|||
return ST_Error; |
|||
case 0x01: |
|||
return ST_TestPrint; |
|||
case 0x02: |
|||
return ST_Busy; |
|||
case 0x03: |
|||
return ST_Wait; |
|||
case 0x04: |
|||
return ST_Idle; |
|||
case 0x05: |
|||
return ST_NotPrint; |
|||
case 0x06: |
|||
return ST_Inkdrying; |
|||
case 0x07: |
|||
return ST_Cleaning; |
|||
default: |
|||
return null; |
|||
} |
|||
} |
|||
} |
|||
|
|||
//------------------------------------
|
|||
//Definitions Printer ErrorCode for TM-C3400/TM-C3500/TM-C7500 (printer type).
|
|||
//Please add ErrorCode which are not being defined.
|
|||
//Some value that is not being defined in enum by specification change of SDK may be returned.
|
|||
//Refer SDK specifications for the latest definition.
|
|||
//------------------------------------
|
|||
public enum ErrorCode |
|||
{ |
|||
ERR_FatalError (0x00 ), |
|||
ERR_CoverOpen (0x02 ), |
|||
ERR_PaperJam (0x04 ), |
|||
ERR_Inkout (0x05 ), |
|||
ERR_Paperout (0x06 ); |
|||
|
|||
private int i; |
|||
ErrorCode(int i) { |
|||
this.i = i; |
|||
} |
|||
|
|||
public int getI() { |
|||
return i; |
|||
} |
|||
|
|||
/** |
|||
* 用于获取对应的枚举值 |
|||
* @param i |
|||
* @return |
|||
*/ |
|||
public static ErrorCode getErrorCode(int i){ |
|||
switch (i){ |
|||
case 0x00: |
|||
return ERR_FatalError; |
|||
case 0x02: |
|||
return ERR_CoverOpen; |
|||
case 0x04: |
|||
return ERR_PaperJam; |
|||
case 0x05: |
|||
return ERR_Inkout; |
|||
case 0x06: |
|||
return ERR_Paperout; |
|||
default: |
|||
return null; |
|||
} |
|||
} |
|||
} |
|||
|
|||
//------------------------------------
|
|||
//Definitions Printer WarningCode for TM-C3400/TM-C3500/TM-C7500 (printer type).
|
|||
//Please add WarningCode which are not being defined.
|
|||
//Some value that is not being defined in enum by specification change of SDK may be returned.
|
|||
//Refer SDK specifications for the latest definition.
|
|||
//------------------------------------
|
|||
public enum WarningCode |
|||
{ |
|||
WAR_InkLow_B (0x010 ), |
|||
WAR_InkLow_C (0x011 ), |
|||
WAR_InkLow_M (0x012 ), |
|||
WAR_InkLow_Y (0x013 ); |
|||
|
|||
private int i; |
|||
WarningCode(int i) { |
|||
this.i = i; |
|||
} |
|||
|
|||
public int getI() { |
|||
return i; |
|||
} |
|||
|
|||
/** |
|||
* 用于获取对应的枚举值 |
|||
* @param i |
|||
* @return |
|||
*/ |
|||
public static WarningCode getWarningCode(int i){ |
|||
switch (i){ |
|||
case 0x010: |
|||
return WAR_InkLow_B; |
|||
case 0x011: |
|||
return WAR_InkLow_C; |
|||
case 0x012: |
|||
return WAR_InkLow_M; |
|||
case 0x013: |
|||
return WAR_InkLow_Y; |
|||
|
|||
default: |
|||
return null; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,231 @@ |
|||
package com.dreamchaser.depository_manage.EPSON.ENS; |
|||
|
|||
import com.dreamchaser.depository_manage.config.EPSON.ENS.Global_MEDIA_ENS; |
|||
import com.dreamchaser.depository_manage.config.EPSON.EPDM.Global_MEDIA_EPDM; |
|||
import com.sun.jna.Memory; |
|||
import com.sun.jna.Structure; |
|||
|
|||
public class ENSStatus extends ENS{ |
|||
|
|||
public class STATUSVERSION extends Structure |
|||
{ |
|||
public short MajorVersion; |
|||
public short MinerVersion; |
|||
} |
|||
|
|||
public class PAPERPATHINFO extends Structure |
|||
{ |
|||
public byte Type; |
|||
public byte Path; |
|||
} |
|||
|
|||
public class CHARASTATUSINFO01 extends Structure |
|||
{ |
|||
public byte Version; |
|||
public int StartDate; |
|||
public int TotalPrintedLine; |
|||
public short TotalTime; |
|||
public short CSFBin1PaperSize; |
|||
public short CSFBin2PaperSize; |
|||
public short CSFBin3PaperSize; |
|||
public short SeriesPaperWidth; |
|||
} |
|||
|
|||
public class CHARASTATUSINFO02 extends Structure |
|||
{ |
|||
public byte Version; |
|||
public int StartDate; |
|||
public int TotalPrintedLine; |
|||
public short TotalTime; |
|||
public int ChangeRibonLine; |
|||
} |
|||
|
|||
public class CHARASTATUSINFO03 extends Structure |
|||
{ |
|||
public byte Version; |
|||
public short CSFBin1PaperSize; |
|||
public byte CSFBin1PaperType; |
|||
public byte CSFBin1PaperRest; |
|||
public short CSFBin2PaperSize; |
|||
public byte CSFBin2PaperType; |
|||
public byte CSFBin2PaperRest; |
|||
public byte SIMMVolume; |
|||
} |
|||
|
|||
|
|||
public class TRAYFIELDINFO extends Structure |
|||
{ |
|||
public byte FieldType; |
|||
public byte Position; |
|||
} |
|||
|
|||
public class PAPERTRAYINFO extends Structure |
|||
{ |
|||
public byte TrayType; |
|||
public byte TrayVolume; |
|||
public TRAYFIELDINFO TrayField; |
|||
} |
|||
|
|||
public class JOBNAMEINFO extends Structure |
|||
{ |
|||
public int JobID; |
|||
public char[] Jobname = new char[64]; |
|||
} |
|||
|
|||
public class CARTRIDGEANDINKINFO extends Structure |
|||
{ |
|||
public byte CartridgeType; |
|||
public int ColorType; |
|||
public byte InkRest; |
|||
public byte InkDimension; |
|||
} |
|||
|
|||
|
|||
public class HEATERTEMPERATUREINFO extends Structure |
|||
{ |
|||
public byte TemperatureUnit; |
|||
public byte TemperatureSetForPreHeater; |
|||
public byte PreHeaterTemperature; |
|||
public byte PreHeaterInfo; |
|||
public byte TemperatureSetForPlatenHeater; |
|||
public byte PlatenHeaterTemperature; |
|||
public byte PlatenHeaterInfo; |
|||
public byte TemperatureSetForAfterHeater; |
|||
public byte AfterHeaterTemperature; |
|||
public byte AfterHeaterInfo; |
|||
} |
|||
|
|||
public class ROMCODEINFO extends Structure |
|||
{ |
|||
public byte Size; |
|||
public byte[] Data = new byte[255]; |
|||
} |
|||
|
|||
public static class INKSIDMSTATUS_02 extends Structure |
|||
{ |
|||
public int StatusSize; |
|||
public STATUSVERSION Version; |
|||
public byte StatusCode; |
|||
public byte ErrorCode; |
|||
public byte SelfPrintCode; |
|||
|
|||
public int[] WarmingCode = new int[2]; |
|||
public byte[] RestCSFPaper = new byte[4]; |
|||
public byte[] ReserveRestCSFPaper = new byte[4]; |
|||
public PAPERPATHINFO PaperPath; |
|||
public short PaperSizeError; |
|||
public byte PaperTypeError; |
|||
public PAPERPATHINFO PaperPathError; |
|||
public CHARASTATUSINFO01 CharaStatus01; |
|||
public CHARASTATUSINFO02 CharaStatus02; |
|||
public CHARASTATUSINFO03 CharaStatus03; |
|||
public short CopyPrintNumber; |
|||
public byte InkColorNumber; |
|||
public byte MicroWeaveInfo; |
|||
public short CleaningTime; |
|||
public byte[] PaperSelectStatus = new byte[11]; |
|||
public byte[] ReservePaperSelectStatus = new byte[5]; |
|||
public CARTRIDGEANDINKINFO[] CartridgeInk = new CARTRIDGEANDINKINFO[16]; |
|||
public PAPERTRAYINFO[] PaperTray = new PAPERTRAYINFO[8]; |
|||
public byte PrintTec; |
|||
public int ReplaceCartridge; |
|||
public short RomCode; |
|||
public byte[] InkRemainInfo = new byte[3]; |
|||
public byte[] ReserveInkRemainInfo = new byte[5]; |
|||
public byte CancelCode; |
|||
public byte CutterInfo; |
|||
public byte PaperJamInfo; |
|||
public byte RouteChangeLeverInfo; |
|||
public JOBNAMEINFO JobNameInfo; |
|||
public int ColorimetricCalibrationIDSize; |
|||
public byte[] ColorimetricCalibrationID = new byte[260]; |
|||
public byte PaperRestUnit; |
|||
public int PaperRestValue; |
|||
public short PaperWidth; |
|||
public byte PaperInfoType; |
|||
public byte PaperInfoValue; |
|||
public byte InkSelect; |
|||
public HEATERTEMPERATUREINFO HeaterTemperature; |
|||
public byte AvailableWarningCode2; |
|||
public byte[] WarningCode2 = new byte[16]; |
|||
public byte PrinterMachineInfo2SetFlag; |
|||
public byte[] PrinterMachineInfo2 = new byte[4]; |
|||
public byte FatalErrorCodeSetFlag; |
|||
public byte FatalErrorCode; |
|||
public byte ReprintInfo; |
|||
public byte StatusReplyType; |
|||
public byte[] SerialNo = new byte[10]; |
|||
public byte[] InkMaintenanceLimit = new byte[16]; |
|||
public ROMCODEINFO RomCode2; |
|||
public byte[] Reserved = new byte[194]; |
|||
}; |
|||
|
|||
private boolean _disposed = false; |
|||
public INKSIDMSTATUS_02 _struct; |
|||
|
|||
public byte StatusCode; |
|||
|
|||
public byte getStatusCode() { |
|||
return _struct.StatusCode; |
|||
} |
|||
|
|||
public byte ErrorCode; |
|||
public byte getErrorCode() { |
|||
return _struct.ErrorCode; |
|||
} |
|||
|
|||
public byte[] WarningCode; |
|||
public byte[] getWarningCode() { |
|||
return _struct.WarningCode2; |
|||
} |
|||
public ENSStatus() |
|||
{ |
|||
|
|||
int Size = Integer.SIZE / 8 * 6 + 556 + Short.SIZE / 8 * 5; |
|||
|
|||
_ptrToStruct = new Memory(Size); |
|||
|
|||
_struct = new INKSIDMSTATUS_02(); |
|||
_struct.StatusSize = Size; |
|||
_struct.Version = new STATUSVERSION(); |
|||
_struct.StatusCode = 0; |
|||
_struct.ErrorCode = 0; |
|||
_struct.SelfPrintCode = 0; |
|||
_struct.PaperPath = new PAPERPATHINFO(); |
|||
_struct.PaperSizeError = 0; |
|||
_struct.PaperTypeError = 0; |
|||
_struct.PaperPathError = new PAPERPATHINFO(); |
|||
_struct.CharaStatus01 = new CHARASTATUSINFO01(); |
|||
_struct.CharaStatus02 = new CHARASTATUSINFO02(); |
|||
_struct.CharaStatus03 = new CHARASTATUSINFO03(); |
|||
_struct.CopyPrintNumber = 0; |
|||
_struct.InkColorNumber = 0; |
|||
_struct.MicroWeaveInfo = 0; |
|||
_struct.CleaningTime = 0; |
|||
_struct.PrintTec = 0; |
|||
_struct.ReplaceCartridge = 0; |
|||
_struct.RomCode = 0; |
|||
_struct.CancelCode = 0; |
|||
_struct.CutterInfo = 0; |
|||
_struct.PaperJamInfo = 0; |
|||
_struct.RouteChangeLeverInfo = 0; |
|||
_struct.JobNameInfo = new JOBNAMEINFO(); |
|||
_struct.ColorimetricCalibrationIDSize = 0; |
|||
_struct.PaperRestUnit = 0; |
|||
_struct.PaperRestValue = 0; |
|||
_struct.PaperWidth = 0; |
|||
_struct.PaperInfoType = 0; |
|||
_struct.PaperInfoValue = 0; |
|||
_struct.InkSelect = 0; |
|||
_struct.HeaterTemperature = new HEATERTEMPERATUREINFO(); |
|||
_struct.AvailableWarningCode2 = 0; |
|||
_struct.PrinterMachineInfo2SetFlag = 0; |
|||
_struct.FatalErrorCodeSetFlag = 0; |
|||
_struct.FatalErrorCode = 0; |
|||
|
|||
Global_MEDIA_ENS.integerINKSIDMSTATUS_02Map.put(_ptrToStruct.getInt(0),_struct); |
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
package com.dreamchaser.depository_manage.EPSON.EPDM; |
|||
|
|||
import com.sun.jna.Memory; |
|||
import com.sun.jna.Native; |
|||
import com.sun.jna.Pointer; |
|||
|
|||
public abstract class EPDM { |
|||
|
|||
protected Pointer _ptrToStruct = new Memory(24); |
|||
private boolean _disposed = false; |
|||
|
|||
public Pointer StructurePointer; |
|||
|
|||
public Pointer getStructurePointer() { |
|||
StructureToPtr(); |
|||
return _ptrToStruct; |
|||
} |
|||
|
|||
public abstract void PtrToStructure(); |
|||
public abstract void StructureToPtr(); |
|||
} |
|||
@ -0,0 +1,426 @@ |
|||
package com.dreamchaser.depository_manage.EPSON.EPDM; |
|||
|
|||
|
|||
/** |
|||
* 用于EPDM相关的枚举类 |
|||
*/ |
|||
public class EPDMEnumrations { |
|||
|
|||
|
|||
/** |
|||
* 用于EPDM的错误码 |
|||
*/ |
|||
public enum EPDMErrorCode { |
|||
EPDM_ERR_NORMAL(0), // The function succeeds.
|
|||
EPDM_ERR_CMD(-1), // The command is not supported.
|
|||
EPDM_ERR_PARAM(-2), // The parameter error
|
|||
EPDM_ERR_NOTSUPPORT(-3), // The specified Printer Driver is not supported.
|
|||
EPDM_ERR_DLLNOTFOUND(-4), // Not found the printer specific DLL
|
|||
EPDM_ERR_NOMEM(-5), // Shortage of memory.
|
|||
EPDM_ERR_OPENPRT(-6), // Open fails
|
|||
EPDM_ERR_FAIL(-7), // Any error is occurred.
|
|||
EPDM_ERR_VERSION(-8), // Not Supprot this DLL version.
|
|||
EPDM_ERR_NOTVALID(-9), // The function can not reply valid value.
|
|||
EPDM_ERR_COMMUNICATION(-10), // A communication error.
|
|||
EPDM_ERR_FATAL(-11), // Fatal error.
|
|||
EPDM_ERR_NOTFOUND(-12), // Not found the input data.
|
|||
EPDM_ERR_FILEFORMAT(-13), // Import file format error.
|
|||
EPDM_ERR_READFILE(-14), // The export file is not read.
|
|||
EPDM_ERR_WRITEFILE(-15), // The export file is not write.
|
|||
EPDM_ERR_OVERWRITE(-16), // The export file name is exist(Do not overwrite).
|
|||
EPDM_ERR_LONGERNAME(-17), // The Add Name is longer.
|
|||
EPDM_ERR_MAXDATA(-18), // The Add Data is max.
|
|||
EPDM_ERR_FWVERSION(-19); // The F/W version is old.
|
|||
|
|||
|
|||
private int i; |
|||
|
|||
EPDMErrorCode(int i) { |
|||
this.i = i; |
|||
} |
|||
|
|||
public int getI() { |
|||
return i; |
|||
} |
|||
|
|||
/** |
|||
* 用于获取对应的枚举值 |
|||
* |
|||
* @param s 输入 |
|||
* @return |
|||
*/ |
|||
public static EPDMErrorCode getEPDMErrorCode(int s) { |
|||
switch (s) { |
|||
case 0: |
|||
return EPDM_ERR_NORMAL; |
|||
case -1: |
|||
return EPDM_ERR_CMD; |
|||
case -2: |
|||
return EPDM_ERR_PARAM; |
|||
case -3: |
|||
return EPDM_ERR_NOTSUPPORT; |
|||
case -4: |
|||
return EPDM_ERR_DLLNOTFOUND; |
|||
case -5: |
|||
return EPDM_ERR_NOMEM; |
|||
case -6: |
|||
return EPDM_ERR_OPENPRT; |
|||
case -7: |
|||
return EPDM_ERR_FAIL; |
|||
case -8: |
|||
return EPDM_ERR_VERSION; |
|||
case -9: |
|||
return EPDM_ERR_NOTVALID; |
|||
case -10: |
|||
return EPDM_ERR_COMMUNICATION; |
|||
case -11: |
|||
return EPDM_ERR_FATAL; |
|||
case -12: |
|||
return EPDM_ERR_NOTFOUND; |
|||
case -13: |
|||
return EPDM_ERR_FILEFORMAT; |
|||
case -14: |
|||
return EPDM_ERR_READFILE; |
|||
case -15: |
|||
return EPDM_ERR_WRITEFILE; |
|||
case -16: |
|||
return EPDM_ERR_OVERWRITE; |
|||
case -17: |
|||
return EPDM_ERR_LONGERNAME; |
|||
case -18: |
|||
return EPDM_ERR_MAXDATA; |
|||
case -19: |
|||
return EPDM_ERR_FWVERSION; |
|||
default: |
|||
return null; |
|||
} |
|||
|
|||
} |
|||
|
|||
} |
|||
|
|||
/** |
|||
* 用于打开打印机类型的枚举 |
|||
*/ |
|||
public enum OpenType { |
|||
EPDM_OPENTYPE_CUR(0), // Open with the printer driver's current default DEVMODE data structure.
|
|||
EPDM_OPENTYPE_ORG(1), // Open with the DEVMODE data structure in factory reset.
|
|||
EPDM_OPENTYPE_IN(2); // Open with the DEVMODE data structure specified by the lpDM parameter.
|
|||
|
|||
private int i; |
|||
|
|||
OpenType(int i) { |
|||
this.i = i; |
|||
} |
|||
|
|||
public int getI() { |
|||
return i; |
|||
} |
|||
|
|||
/** |
|||
* 用于获取对应的枚举值 |
|||
* |
|||
* @param i 输入 |
|||
* @return |
|||
*/ |
|||
public static OpenType getEPDMOpenType(int i) { |
|||
switch (i) { |
|||
case 0: |
|||
return EPDM_OPENTYPE_CUR; |
|||
case 1: |
|||
return EPDM_OPENTYPE_ORG; |
|||
case 2: |
|||
return EPDM_OPENTYPE_IN; |
|||
default: |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于控制类型的枚举 |
|||
*/ |
|||
public enum Command { |
|||
EPDM_CMD_MEDIA(60), // Media type
|
|||
EPDM_CMD_STRING(213), // String.
|
|||
EPDM_CMD_FAVORITE(500), // My favorite :Comment=STR
|
|||
EPDM_CMD_FAVORITEW(501), // My favorite :Comment=WSTR
|
|||
EPDM_CMD_MEDIALAYOUT(502), // Media layout :Comment=STR
|
|||
EPDM_CMD_MEDIALAYOUTW(503), // Media layout :Comment=WSTR
|
|||
EPDM_CMD_QUALITY(504), // Print qulity
|
|||
EPDM_CMD_AUTOCUT(505), // Media cut mode
|
|||
EPDM_CMD_AUTOCUTNUM(506), // Count of media cut
|
|||
EPDM_CMD_MEDIAPOSITION(507), // Search media position
|
|||
EPDM_CMD_DRIVERSETTINGS(600), // Driver settings :Comment=STR
|
|||
EPDM_CMD_DRIVERSETTINGSW(601), // Driver settings :Comment=WSTR
|
|||
EPDM_CMD_PRINTERSETTINGS(602), // Printer settings :Comment=STR
|
|||
EPDM_CMD_PRINTERSETTINGSW(603), // Printer settings :Comment=WSTR
|
|||
EPDM_CMD_STRINGW(1024); // UNICODE String.
|
|||
|
|||
private int i; |
|||
|
|||
Command(int i) { |
|||
this.i = i; |
|||
} |
|||
|
|||
public int getI() { |
|||
return i; |
|||
} |
|||
|
|||
/** |
|||
* 用于获取对应的枚举值 |
|||
* |
|||
* @param i 输入 |
|||
* @return |
|||
*/ |
|||
public static Command getCommand(int i) { |
|||
switch (i) { |
|||
case 60: |
|||
return EPDM_CMD_MEDIA; |
|||
case 213: |
|||
return EPDM_CMD_STRING; |
|||
case 500: |
|||
return EPDM_CMD_FAVORITE; |
|||
case 501: |
|||
return EPDM_CMD_FAVORITEW; |
|||
case 502: |
|||
return EPDM_CMD_MEDIALAYOUT; |
|||
case 503: |
|||
return EPDM_CMD_MEDIALAYOUTW; |
|||
case 504: |
|||
return EPDM_CMD_QUALITY; |
|||
case 505: |
|||
return EPDM_CMD_AUTOCUT; |
|||
case 506: |
|||
return EPDM_CMD_AUTOCUTNUM; |
|||
case 507: |
|||
return EPDM_CMD_MEDIAPOSITION; |
|||
case 600: |
|||
return EPDM_CMD_DRIVERSETTINGS; |
|||
case 601: |
|||
return EPDM_CMD_DRIVERSETTINGSW; |
|||
case 602: |
|||
return EPDM_CMD_PRINTERSETTINGS; |
|||
case 603: |
|||
return EPDM_CMD_PRINTERSETTINGSW; |
|||
case 1024: |
|||
return EPDM_CMD_STRINGW; |
|||
|
|||
default: |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于结构类型的枚举 |
|||
*/ |
|||
public enum StructVersion { |
|||
EPDM_STVER_STRING_1(1), // Structure Version define for [EPDM_STRING_1]
|
|||
EPDM_STVER_STRINGW_1(1), // Structure Version define for [EPDM_STRINGW_1]
|
|||
EPDM_STVER_FAVORITEINF(1), // Structure Version define for [EPDM_FAVORITEINF]
|
|||
EPDM_STVER_FAVORITEINFW(1), // Structure Version define for [EPDM_FAVORITEINFW]
|
|||
EPDM_STVER_FAVORITERANGE(1), // Structure Version define for [EPDM_FAVORITERANGE]
|
|||
EPDM_STVER_MEDIALAYOUTINF(1), // Structure Version define for [EPDM_MEDIALAYOUTINF]
|
|||
EPDM_STVER_MEDIALAYOUTINF_2(2), // Structure Version define for [EPDM_MEDIALAYOUTINF_2]
|
|||
EPDM_STVER_MEDIATYPERANGE(1), // Structure Version define for [EPDM_MEDIATYPERANGE]
|
|||
EPDM_STVER_MEDIATYPERANGE_2(2), // Structure Version define for [EPDM_MEDIATYPERANGE_2]
|
|||
EPDM_STVER_MEDIALAYOUTRANGE(1), // Structure Version define for [EPDM_MEDIALAYOUTRANGE]
|
|||
EPDM_STVER_MEDIALAYOUTRANGE_2(2), // Structure Version define for [EPDM_MEDIALAYOUTRANGE_2]
|
|||
EPDM_STVER_MEDIALAYOUTADD(1), // Structure Version define for [EPDM_MEDIALAYOUTADD]
|
|||
EPDM_STVER_MEDIALAYOUTADD_2(2), // Structure Version define for [EPDM_MEDIALAYOUTADD_2]
|
|||
EPDM_STVER_MEDIALAYOUTADDW(1), // Structure Version define for [EPDM_MEDIALAYOUTADDW]
|
|||
EPDM_STVER_MEDIALAYOUTADDW_2(2), // Structure Version define for [EPDM_MEDIALAYOUTADDW_2]
|
|||
EPDM_STVER_PRINTERSETTINGS(1), // Structure Version define for [EPDM_PRINTERSETTINGS]
|
|||
EPDM_STVER_EXPORTDATA(1), // Structure Version define for [EPDM_EXPORTDATA]
|
|||
EPDM_STVER_EXPORTDATAW(1), // Structure Version define for [EPDM_EXPORTDATAW]
|
|||
EPDM_STVER_FAVORITEADD(1), // Structure Version define for [EPDM_FAVORITEADD]
|
|||
EPDM_STVER_FAVORITEADDW(1), // Structure Version define for [EPDM_FAVORITEADDW]
|
|||
EPDM_STVER_EXPORT_DRIVERSETTINGS(1), // Structure Version define for [EPDM_EXPORT_DRIVERSETTINGS]
|
|||
EPDM_STVER_EXPORT_DRIVERSETTINGSW(1), // Structure Version define for [EPDM_EXPORT_DRIVERSETTINGSW]
|
|||
EPDM_STVER_EXPORT_PRINTERSETTINGS(1), // Structure Version define for [EPDM_EXPORT_PRINTERSETTINGS]
|
|||
EPDM_STVER_EXPORT_PRINTERSETTINGSW(1); // Structure Version define for [EPDM_EXPORT_PRINTERSETTINGSW]
|
|||
|
|||
private int i; |
|||
|
|||
StructVersion(int i) { |
|||
this.i = i; |
|||
} |
|||
|
|||
public int getI() { |
|||
return i; |
|||
} |
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于名称的枚举 |
|||
*/ |
|||
public enum StringID |
|||
{ |
|||
EPDM_STRING_MEDIA (3), // Media Name.
|
|||
EPDM_STRING_FAVORITE (15), // Favorite Name
|
|||
EPDM_STRING_MEDIALAYOUT (16), // Media Layout Name
|
|||
EPDM_STRING_MEDIATYPE (17), // Media Type Name
|
|||
EPDM_STRING_AUTOCUT (18), // Autocut Action Type Name
|
|||
EPDM_STRING_MEDIAPOSITION (19); // Media Position Kind Name
|
|||
|
|||
private int i; |
|||
StringID(int i) { |
|||
this.i = i; |
|||
} |
|||
|
|||
public int getI() { |
|||
return i; |
|||
} |
|||
|
|||
public static StringID getStringID(int s) { |
|||
switch (s) { |
|||
case 3: |
|||
return EPDM_STRING_MEDIA; |
|||
case 15: |
|||
return EPDM_STRING_FAVORITE; |
|||
case 16: |
|||
return EPDM_STRING_MEDIALAYOUT; |
|||
case 17: |
|||
return EPDM_STRING_MEDIATYPE; |
|||
case 18: |
|||
return EPDM_STRING_AUTOCUT; |
|||
case 19: |
|||
return EPDM_STRING_MEDIAPOSITION; |
|||
default: |
|||
return null; |
|||
} |
|||
|
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 用于媒体类型的枚举 |
|||
*/ |
|||
public enum MediaTypeID |
|||
{ |
|||
EPDM_MEDIATYPE_DIECUT ((short) 0), // Die-cut Label(Gap)
|
|||
EPDM_MEDIATYPE_BMDIECUT ((short)1), // Die-cut Label(BM)
|
|||
EPDM_MEDIATYPE_BMDIECUTGAP ((short)2), // Black Mark Die-cut Label(Gap)
|
|||
EPDM_MEDIATYPE_ALLLABEL ((short)3), // Full-page Label
|
|||
EPDM_MEDIATYPE_BMALLLABEL ((short)4), // Black Mark Full-page Label
|
|||
EPDM_MEDIATYPE_RECEIPT ((short)5), // Continuous Paper
|
|||
EPDM_MEDIATYPE_BMRECEIPT ((short)6), // Black Mark Continuous Paper
|
|||
EPDM_MEDIATYPE_TPDIECUT ((short)7), // Transparent Die-cut Label
|
|||
EPDM_MEDIATYPE_TPALLLABEL ((short)8); // Transparent Full-page Label
|
|||
|
|||
private short i; |
|||
|
|||
|
|||
MediaTypeID(short i) { |
|||
this.i = i; |
|||
} |
|||
|
|||
public short getI() { |
|||
return i; |
|||
} |
|||
|
|||
public static MediaTypeID getMediaTypeID(short s) { |
|||
switch (s) { |
|||
case 0: |
|||
return EPDM_MEDIATYPE_DIECUT; |
|||
case 1: |
|||
return EPDM_MEDIATYPE_BMDIECUT; |
|||
case 2: |
|||
return EPDM_MEDIATYPE_BMDIECUTGAP; |
|||
case 3: |
|||
return EPDM_MEDIATYPE_ALLLABEL; |
|||
case 4: |
|||
return EPDM_MEDIATYPE_BMALLLABEL; |
|||
case 5: |
|||
return EPDM_MEDIATYPE_RECEIPT; |
|||
case 6: |
|||
return EPDM_MEDIATYPE_BMRECEIPT; |
|||
case 7: |
|||
return EPDM_MEDIATYPE_TPDIECUT; |
|||
case 8: |
|||
return EPDM_MEDIATYPE_TPALLLABEL; |
|||
default: |
|||
return null; |
|||
} |
|||
|
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于打印质量的枚举 |
|||
*/ |
|||
public enum PrintQualityID |
|||
{ |
|||
EPDM_QUALITY_360X180 (0), // Quality level (360dpi * 180dpi)
|
|||
EPDM_QUALITY_360X360 (1), // Quality level (360dpi * 360dpi)
|
|||
EPDM_QUALITY_720X360 (2); // Quality level (720dpi * 360dpi)
|
|||
|
|||
|
|||
private int i; |
|||
|
|||
PrintQualityID(int i) { |
|||
this.i = i; |
|||
} |
|||
|
|||
public int getI() { |
|||
return i; |
|||
} |
|||
|
|||
public static PrintQualityID getPrintQualityID(int s) { |
|||
switch (s) { |
|||
case 0: |
|||
return EPDM_QUALITY_360X180; |
|||
case 1: |
|||
return EPDM_QUALITY_360X360; |
|||
case 2: |
|||
return EPDM_QUALITY_720X360; |
|||
default: |
|||
return null; |
|||
} |
|||
|
|||
} |
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于打印机状态的枚举 |
|||
*/ |
|||
public enum OverWriteID |
|||
{ |
|||
EPDM_OVERWRITE_OFF (0), // Disable over write
|
|||
EPDM_OVERWRITE_ON (1); // Enable over write
|
|||
|
|||
|
|||
private int i; |
|||
OverWriteID(int i) { |
|||
this.i = i; |
|||
} |
|||
|
|||
public int getI() { |
|||
return i; |
|||
} |
|||
|
|||
public static OverWriteID getOverWriteID(int s) { |
|||
switch (s) { |
|||
case 0: |
|||
return EPDM_OVERWRITE_OFF; |
|||
case 1: |
|||
return EPDM_OVERWRITE_ON; |
|||
default: |
|||
return null; |
|||
} |
|||
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,214 @@ |
|||
package com.dreamchaser.depository_manage.EPSON.EPDM; |
|||
|
|||
import com.dreamchaser.depository_manage.EPSON.epsonException.EPDMException; |
|||
import com.dreamchaser.depository_manage.config.EPSON.EPDM.Global_MEDIA_EPDM; |
|||
import com.dreamchaser.depository_manage.exception.MyException; |
|||
import com.sun.jna.Memory; |
|||
import com.sun.jna.Native; |
|||
import com.sun.jna.Pointer; |
|||
import com.sun.jna.Structure; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.Arrays; |
|||
import java.util.Collections; |
|||
import java.util.List; |
|||
|
|||
public class EPDMMediaLayoutRange extends EPDM{ |
|||
|
|||
|
|||
|
|||
|
|||
public class EPDM_MEDIALAYOUTRANGE extends Structure |
|||
{ |
|||
public int dwVersion; |
|||
public int dwSize; |
|||
public short iIDCount; |
|||
public short iMediaTypeCount; |
|||
public Pointer lpMediaLayoutID; |
|||
public Pointer lpMediaTypeRange; |
|||
public short iMaxString; |
|||
public short iMaxCount; |
|||
|
|||
|
|||
@Override |
|||
protected List<String> getFieldOrder() { |
|||
return new ArrayList<>(Arrays.asList("dwVersion", "dwSize", "iIDCount", "iMediaTypeCount", "lpMediaLayoutID", "lpMediaTypeRange", "iMaxString", "iMaxCount")); |
|||
} |
|||
|
|||
public EPDM_MEDIALAYOUTRANGE() { |
|||
|
|||
} |
|||
|
|||
public EPDM_MEDIALAYOUTRANGE(Pointer p) { |
|||
super(p); |
|||
} |
|||
|
|||
}; |
|||
|
|||
private boolean _disposed = false; |
|||
private EPDM_MEDIALAYOUTRANGE _struct; |
|||
|
|||
|
|||
|
|||
public EPDMEnumrations.StructVersion Version; |
|||
|
|||
|
|||
public short IDCount; |
|||
|
|||
public short getIDCount() { |
|||
return _struct.iIDCount; |
|||
} |
|||
|
|||
|
|||
public short[] MediaLayoutID; |
|||
|
|||
public short[] getMediaLayoutID() { |
|||
|
|||
try |
|||
{ |
|||
short[] arr = new short[_struct.iIDCount]; |
|||
|
|||
for (int i = 0; i < _struct.iIDCount; i++) |
|||
{ |
|||
Pointer current = new Memory(_struct.lpMediaLayoutID.getLong(0) + (2 * i)); |
|||
|
|||
arr[i] = Global_MEDIA_EPDM.epdm_mediaLayoutRange_short.get(current.getInt(0)); |
|||
} |
|||
return arr; |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
return null; |
|||
|
|||
} |
|||
|
|||
|
|||
public EPDMMediaTypeRange.EPDM_MEDIATYPERANGE[] MediaTypeRange; |
|||
|
|||
public EPDMMediaTypeRange.EPDM_MEDIATYPERANGE[] getMediaTypeRange() { |
|||
try |
|||
{ |
|||
EPDMMediaTypeRange.EPDM_MEDIATYPERANGE[] arr = new EPDMMediaTypeRange.EPDM_MEDIATYPERANGE[_struct.iMediaTypeCount]; |
|||
|
|||
int struct_size = 22 * Short.SIZE / 8 + 2 * Integer.SIZE / 8; |
|||
|
|||
for (int i = 0; i < _struct.iMediaTypeCount; i++) |
|||
{ |
|||
Pointer current = new Memory(_struct.lpMediaTypeRange.getInt(0) + (struct_size) * i); |
|||
arr[i] = Global_MEDIA_EPDM.epdm_mediatyperangeMap.get(current.getInt(0)); |
|||
} |
|||
return arr; |
|||
} |
|||
catch (Exception e) |
|||
{ |
|||
// Error handling.
|
|||
System.out.println(e.getMessage()); |
|||
} |
|||
return MediaTypeRange; |
|||
} |
|||
|
|||
public EPDMMediaLayoutRange() { |
|||
|
|||
int struct_size = 24; |
|||
_ptrToStruct = new Memory(struct_size); |
|||
_struct = new EPDM_MEDIALAYOUTRANGE(_ptrToStruct); |
|||
_struct.dwVersion = EPDMEnumrations.StructVersion.EPDM_STVER_MEDIALAYOUTRANGE.getI(); |
|||
_struct.dwSize = struct_size; |
|||
_struct.iIDCount = 0; |
|||
_struct.iMediaTypeCount = 0; |
|||
_struct.lpMediaLayoutID = new Memory(10); |
|||
_struct.lpMediaTypeRange = new Memory(10); |
|||
_struct.iMaxString = 0; |
|||
_struct.iMaxCount = 0; |
|||
|
|||
StructureToPtr(); |
|||
PtrToStructure(); |
|||
} |
|||
|
|||
@Override |
|||
public void PtrToStructure() { |
|||
_struct.read(); |
|||
_struct = Global_MEDIA_EPDM.epdm_medialayoutrangeMap.get(_ptrToStruct.getInt(0)); |
|||
|
|||
} |
|||
|
|||
@Override |
|||
public void StructureToPtr() { |
|||
_struct.write(); |
|||
Global_MEDIA_EPDM.epdm_medialayoutrangeMap.put(_ptrToStruct.getInt(0),_struct); |
|||
} |
|||
|
|||
public void Alloc() |
|||
{ |
|||
try |
|||
{ |
|||
// iIDCount、iMediaTypeCount = 0 is EPDM_ERR_FAIL.
|
|||
if (_struct.iIDCount == 0 || _struct.iMediaTypeCount == 0) |
|||
{ |
|||
throw new EPDMException(EPDMEnumrations.EPDMErrorCode.EPDM_ERR_FAIL); |
|||
} |
|||
|
|||
|
|||
|
|||
// Free the memory.
|
|||
Native.free(Pointer.nativeValue(_struct.lpMediaLayoutID)); |
|||
Native.free(Pointer.nativeValue(_struct.lpMediaTypeRange)); |
|||
|
|||
|
|||
_struct.lpMediaLayoutID = new Memory(_struct.iIDCount * Short.SIZE / 8); |
|||
|
|||
int sizeOfEPDM_MEDIATYPERANGE = (22 * Short.SIZE / 8 + 2 * Integer.SIZE / 8); |
|||
|
|||
_struct.lpMediaTypeRange = new Memory(_struct.iMediaTypeCount *sizeOfEPDM_MEDIATYPERANGE ).getPointer(0); |
|||
|
|||
EPDMMediaTypeRange.EPDM_MEDIATYPERANGE[] epdmMediaTypeRange = new EPDMMediaTypeRange.EPDM_MEDIATYPERANGE[_struct.iMediaTypeCount]; |
|||
for (int i = 0; i < _struct.iMediaTypeCount; i++) |
|||
{ |
|||
Pointer current = new Memory(_ptrToStruct.getLong(0) + (sizeOfEPDM_MEDIATYPERANGE * i)); |
|||
epdmMediaTypeRange[i] = Global_MEDIA_EPDM.epdm_mediatyperangeMap.get(current.getInt(0)); |
|||
|
|||
epdmMediaTypeRange[i].dwVersion = EPDMEnumrations.StructVersion.EPDM_STVER_MEDIATYPERANGE.getI(); |
|||
epdmMediaTypeRange[i].dwSize = (22 * Short.SIZE / 8 + 2 * Integer.SIZE / 8); |
|||
|
|||
Pointer current2 = new Memory(_struct.lpMediaTypeRange.getLong(0) + (sizeOfEPDM_MEDIATYPERANGE * i)); |
|||
Global_MEDIA_EPDM.epdm_mediatyperangeMap.put(current2.getInt(0),epdmMediaTypeRange[i]); |
|||
} |
|||
} |
|||
catch (Exception e) |
|||
{ |
|||
// Error handling.
|
|||
System.out.println(e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
public int GetMediaTypeIndex(EPDMEnumrations.MediaTypeID mediaTypeID) |
|||
{ |
|||
try |
|||
{ |
|||
int i = -1; |
|||
|
|||
if (_struct.iMediaTypeCount <= 0) |
|||
{ |
|||
return i; |
|||
} |
|||
|
|||
for (i = 0; i < _struct.iMediaTypeCount; i++) |
|||
{ |
|||
short typeID = MediaTypeRange[i].iTypeID; |
|||
if (typeID == mediaTypeID.getI()) |
|||
{ |
|||
break; |
|||
} |
|||
} |
|||
return i; |
|||
} |
|||
catch (Exception e) |
|||
{ |
|||
// Error handling.
|
|||
throw new MyException(e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,125 @@ |
|||
package com.dreamchaser.depository_manage.EPSON.EPDM; |
|||
|
|||
import com.dreamchaser.depository_manage.config.EPSON.EPDM.Global_MEDIA_EPDM; |
|||
import com.sun.jna.Memory; |
|||
import com.sun.jna.Pointer; |
|||
import com.sun.jna.Structure; |
|||
import com.sun.xml.bind.v2.runtime.MarshallerImpl; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
|
|||
public class EPDMMediaTypeRange extends EPDM { |
|||
|
|||
@Override |
|||
public void PtrToStructure() { |
|||
_struct.read(); |
|||
_struct = Global_MEDIA_EPDM.epdm_mediatyperangeMap.get(_ptrToStruct.getInt(0)); |
|||
} |
|||
|
|||
@Override |
|||
public void StructureToPtr() { |
|||
_struct.write(); |
|||
Global_MEDIA_EPDM.epdm_mediatyperangeMap.put(_ptrToStruct.getInt(0),_struct); |
|||
} |
|||
|
|||
public class EPDM_MEDIATYPERANGE extends Structure |
|||
{ |
|||
public int dwVersion; |
|||
public int dwSize; |
|||
public short iMaxPaperWid; |
|||
public short iMaxPaperHig; |
|||
public short iMaxLabelWid; |
|||
public short iMaxLabelHig; |
|||
public short iMaxLabelGap; |
|||
public short iMaxBMGap; |
|||
public short iMaxPrintWid; |
|||
public short iMaxPrintHig; |
|||
public short iMaxPrintX; |
|||
public short iMaxPrintY; |
|||
public short iMinPaperWid; |
|||
public short iMinPaperHig; |
|||
public short iMinLabelWid; |
|||
public short iMinLabelHig; |
|||
public short iMinLabelGap; |
|||
public short iMinBMGap; |
|||
public short iMinPrintWid; |
|||
public short iMinPrintHig; |
|||
public short iMinPrintX; |
|||
public short iMinPrintY; |
|||
public short iTypeID; |
|||
public short iRsv; |
|||
|
|||
@Override |
|||
protected List<String> getFieldOrder() { |
|||
return new ArrayList<>(Arrays.asList("dwVersion", "dwSize", "iMaxPaperWid", "iMaxPaperHig", "iMaxLabelWid", "iMaxLabelHig", |
|||
"iMaxLabelGap", "iMaxBMGap","iMaxPrintWid","iMaxPrintHig","iMaxPrintX","iMaxPrintY","iMinPaperWid","iMinPaperHig", |
|||
"iMinLabelWid","iMinLabelHig","iMinLabelGap","iMinBMGap","iMinPrintWid","iMinPrintHig","iMinPrintX","iMinPrintY", |
|||
"iTypeID","iRsv")); |
|||
} |
|||
|
|||
public EPDM_MEDIATYPERANGE() { |
|||
|
|||
} |
|||
|
|||
public EPDM_MEDIATYPERANGE(Pointer p) { |
|||
super(p); |
|||
} |
|||
|
|||
}; |
|||
|
|||
private boolean _disposed = false; |
|||
public EPDM_MEDIATYPERANGE _struct; |
|||
|
|||
|
|||
public short MaxPaperWid; |
|||
|
|||
public short getMaxPaperWid() { |
|||
return _struct.iMaxPaperWid; |
|||
} |
|||
|
|||
public short MaxPaperHig; |
|||
|
|||
public short getMaxPaperHig() { |
|||
return _struct.iMaxPaperHig; |
|||
} |
|||
|
|||
public EPDMMediaTypeRange() |
|||
{ |
|||
|
|||
int struct_size = 22 * Short.SIZE / 8 + 2 * Integer.SIZE / 8; |
|||
|
|||
_ptrToStruct =new Memory(struct_size ); |
|||
_struct = new EPDM_MEDIATYPERANGE(_ptrToStruct); |
|||
_struct.dwVersion = EPDMEnumrations.StructVersion.EPDM_STVER_MEDIATYPERANGE.getI(); |
|||
_struct.dwSize = struct_size; |
|||
_struct.iMaxPaperWid = 0; |
|||
_struct.iMaxPaperHig = 0; |
|||
_struct.iMaxLabelWid = 0; |
|||
_struct.iMaxLabelHig = 0; |
|||
_struct.iMaxLabelGap = 0; |
|||
_struct.iMaxBMGap = 0; |
|||
_struct.iMaxPrintWid = 0; |
|||
_struct.iMaxPrintHig = 0; |
|||
_struct.iMaxPrintX = 0; |
|||
_struct.iMaxPrintY = 0; |
|||
_struct.iMinPaperWid = 0; |
|||
_struct.iMinPaperHig = 0; |
|||
_struct.iMinLabelWid = 0; |
|||
_struct.iMinLabelHig = 0; |
|||
_struct.iMinLabelGap = 0; |
|||
_struct.iMinBMGap = 0; |
|||
_struct.iMinPrintWid = 0; |
|||
_struct.iMinPrintHig = 0; |
|||
_struct.iMinPrintX = 0; |
|||
_struct.iMinPrintY = 0; |
|||
_struct.iTypeID = EPDMEnumrations.MediaTypeID.EPDM_MEDIATYPE_DIECUT.getI(); |
|||
_struct.iRsv = 0; |
|||
|
|||
StructureToPtr(); |
|||
PtrToStructure(); |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,152 @@ |
|||
package com.dreamchaser.depository_manage.EPSON.EPDM; |
|||
|
|||
import com.dreamchaser.depository_manage.EPSON.epsonException.EPDMException; |
|||
import com.dreamchaser.depository_manage.config.EPSON.EPDM.Global_MEDIA_EPDM; |
|||
import com.dreamchaser.depository_manage.exception.MyException; |
|||
import com.dreamchaser.depository_manage.utils.ObjectFormatUtil; |
|||
import com.sun.jna.Memory; |
|||
import com.sun.jna.Native; |
|||
import com.sun.jna.Pointer; |
|||
import com.sun.jna.Structure; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
|
|||
public class EPDMSelectData extends EPDM{ |
|||
|
|||
@Override |
|||
public void PtrToStructure() { |
|||
_struct.read(); |
|||
_struct = Global_MEDIA_EPDM.epdm_selectdataMap.get(_ptrToStruct.getInt(0)); |
|||
} |
|||
|
|||
@Override |
|||
public void StructureToPtr() { |
|||
_struct.write(); |
|||
Global_MEDIA_EPDM.epdm_selectdataMap.put(_ptrToStruct.getInt(0),_struct); |
|||
} |
|||
|
|||
public static class EPDM_SELECTDATA extends Structure |
|||
{ |
|||
public short iCount; |
|||
public short iSize; |
|||
public Pointer lpData; |
|||
|
|||
@Override |
|||
protected List<String> getFieldOrder() { |
|||
return new ArrayList<>(Arrays.asList("iCount", "iSize", "lpData")); |
|||
} |
|||
|
|||
public EPDM_SELECTDATA(Pointer p) { |
|||
super(p); |
|||
} |
|||
|
|||
public EPDM_SELECTDATA() { |
|||
} |
|||
}; |
|||
|
|||
|
|||
private boolean _disposed = false; |
|||
private EPDM_SELECTDATA _struct; |
|||
|
|||
|
|||
public short Count; |
|||
|
|||
|
|||
public Long[] Data; |
|||
|
|||
|
|||
public short getCount() { |
|||
return _struct.iCount; |
|||
} |
|||
|
|||
public Long[] getData() { |
|||
try |
|||
{ |
|||
if (_struct.lpData == Pointer.NULL || _struct.iSize > Long.SIZE / 8) |
|||
{ |
|||
return null; |
|||
} |
|||
|
|||
Long[] arr = new Long[_struct.iCount]; |
|||
|
|||
for (int i = 0; i < _struct.iCount; i++) |
|||
{ |
|||
Pointer current = new Memory(_struct.lpData.getLong(0) + (_struct.iSize * i)); |
|||
arr[i] = GetSelectData(current); |
|||
} |
|||
return arr; |
|||
} |
|||
catch (Exception e) |
|||
{ |
|||
// Error handling.
|
|||
throw new MyException(e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
|
|||
public EPDMSelectData() |
|||
{ |
|||
_ptrToStruct = new Memory(Short.SIZE / 8 * 2); |
|||
|
|||
_struct.iCount = 0; |
|||
_struct.iSize = 0; |
|||
_struct.lpData = new Memory(10); |
|||
|
|||
|
|||
StructureToPtr(); |
|||
PtrToStructure(); |
|||
} |
|||
|
|||
|
|||
private Long GetSelectData(Pointer p) |
|||
{ |
|||
try |
|||
{ |
|||
Long data = 0L; |
|||
switch (_struct.iSize) |
|||
{ |
|||
case 8: |
|||
data = Global_MEDIA_EPDM.epdm_select_data_int64.get(p.getInt(0)); |
|||
break; |
|||
case 4: |
|||
data = ObjectFormatUtil.toLong(Global_MEDIA_EPDM.epdm_select_data_int32.get(p.getInt(0))); |
|||
break; |
|||
case 2: |
|||
default: |
|||
data = ObjectFormatUtil.toLong(Global_MEDIA_EPDM.epdm_select_data_int16.get(p.getInt(0))); |
|||
break; |
|||
} |
|||
return data; |
|||
} |
|||
catch (Exception e) |
|||
{ |
|||
// Error handling.
|
|||
throw new MyException(e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
|
|||
public void Alloc() |
|||
{ |
|||
try |
|||
{ |
|||
// iIDCount、iSize = 0 is EPDM_ERR_FAIL.
|
|||
if (_struct.iCount == 0 || _struct.iSize == 0) |
|||
{ |
|||
throw new EPDMException(EPDMEnumrations.EPDMErrorCode.EPDM_ERR_FAIL); |
|||
} |
|||
|
|||
// Free the memory.
|
|||
Native.free(Pointer.nativeValue(_struct.lpData)); |
|||
// Allocate the memory. - EPDMSelectData.lpData
|
|||
_struct.lpData =new Memory(_struct.iCount * _struct.iSize); |
|||
} |
|||
catch (Exception e) |
|||
{ |
|||
// Error handling.
|
|||
throw new MyException(e.getMessage()); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,150 @@ |
|||
package com.dreamchaser.depository_manage.EPSON.EPDM; |
|||
|
|||
import com.dreamchaser.depository_manage.EPSON.epsonException.EPDMException; |
|||
import com.dreamchaser.depository_manage.config.EPSON.EPDM.Global_MEDIA_EPDM; |
|||
import com.dreamchaser.depository_manage.exception.MyException; |
|||
import com.sun.jna.Memory; |
|||
import com.sun.jna.Native; |
|||
import com.sun.jna.Pointer; |
|||
import com.sun.jna.Structure; |
|||
import com.sun.media.jfxmedia.track.Track; |
|||
import jdk.nashorn.internal.objects.Global; |
|||
|
|||
import java.io.UnsupportedEncodingException; |
|||
import java.util.ArrayList; |
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
import java.util.Locale; |
|||
|
|||
public class EPDMString extends EPDM { |
|||
|
|||
public class EPDM_STRING_1 extends Structure |
|||
{ |
|||
public int dwVersion; |
|||
public int dwSize; |
|||
public int dwStrSize; |
|||
public int dwCommand; |
|||
public int dwID; |
|||
public Pointer lpString; |
|||
|
|||
|
|||
@Override |
|||
protected List<String> getFieldOrder() { |
|||
return new ArrayList<>(Arrays.asList("dwVersion", "dwSize", "dwStrSize", "dwCommand", "dwID", "lpString")); |
|||
} |
|||
|
|||
public EPDM_STRING_1() { |
|||
} |
|||
|
|||
public EPDM_STRING_1(Pointer p) { |
|||
super(p); |
|||
} |
|||
}; |
|||
|
|||
private boolean _disposed = false; |
|||
private EPDM_STRING_1 _struct; |
|||
|
|||
public int Command; |
|||
|
|||
public int getCommand() { |
|||
return _struct.dwCommand; |
|||
} |
|||
|
|||
public void setCommand(int command) { |
|||
_struct.dwCommand = command; |
|||
} |
|||
|
|||
public int ID; |
|||
|
|||
public int getID() { |
|||
return _struct.dwID; |
|||
} |
|||
|
|||
public void setID(int ID) { |
|||
_struct.dwID = ID; |
|||
} |
|||
|
|||
|
|||
|
|||
public String string; |
|||
|
|||
public String getString() { |
|||
byte[] StringData = new byte[_struct.dwStrSize]; |
|||
|
|||
// Deploy the memory to array.
|
|||
int i = 0; |
|||
for (i = 0; i < _struct.dwStrSize; i++) |
|||
{ |
|||
Pointer current = new Memory(_struct.lpString.getLong(0) + i); |
|||
// StringData[i]= current.getByte(0);
|
|||
StringData[i] = Global_MEDIA_EPDM.epdm_epdmString_byte.get(current.getInt(0)); |
|||
if (StringData[i] == 0) |
|||
{ |
|||
break; |
|||
} |
|||
} |
|||
try { |
|||
return new String(StringData,"gbk"); |
|||
} catch (UnsupportedEncodingException e) { |
|||
throw new MyException(e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
public EPDMString() |
|||
{ |
|||
|
|||
|
|||
int structSize = 5 * Integer.SIZE / 8; |
|||
_ptrToStruct = new Memory( structSize ); |
|||
|
|||
_struct = new EPDM_STRING_1(_ptrToStruct); |
|||
_struct.dwVersion = EPDMEnumrations.StructVersion.EPDM_STVER_STRING_1.getI(); |
|||
_struct.dwSize = structSize; |
|||
_struct.dwStrSize = 0; |
|||
_struct.dwCommand = 0; |
|||
_struct.dwID = 0; |
|||
_struct.lpString = new Memory(10); |
|||
StructureToPtr(); |
|||
PtrToStructure(); |
|||
} |
|||
|
|||
|
|||
@Override |
|||
public void PtrToStructure() { |
|||
_struct.read(); |
|||
_struct = Global_MEDIA_EPDM.epdm_string_1Map.get(_ptrToStruct.getInt(0)); |
|||
} |
|||
|
|||
@Override |
|||
public void StructureToPtr() { |
|||
_struct.write(); |
|||
Global_MEDIA_EPDM.epdm_string_1Map.put(_ptrToStruct.getInt(0),_struct); |
|||
} |
|||
|
|||
|
|||
public void Alloc() |
|||
{ |
|||
try |
|||
{ |
|||
// m_Struct.dwStrSize == 0 is EPDM_ERR_FAIL.
|
|||
if (_struct.dwStrSize == 0) |
|||
{ |
|||
throw new EPDMException(EPDMEnumrations.EPDMErrorCode.EPDM_ERR_FAIL); |
|||
} |
|||
|
|||
// Free the memory.
|
|||
Native.free(Pointer.nativeValue(_struct.lpString)); |
|||
|
|||
// Allocate the memory. - EPDMString.lpString
|
|||
_struct.lpString =new Memory((int)_struct.dwStrSize); |
|||
} |
|||
catch (Exception e) |
|||
{ |
|||
// Error handling.
|
|||
throw new MyException(e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,301 @@ |
|||
package com.dreamchaser.depository_manage.EPSON.Other; |
|||
|
|||
import com.dreamchaser.depository_manage.EPSON.ENS.ENSEnumrations; |
|||
import com.dreamchaser.depository_manage.EPSON.ENS.ENSEnumrations.StatusCode; |
|||
import com.dreamchaser.depository_manage.EPSON.EPDM.EPDMEnumrations; |
|||
import com.dreamchaser.depository_manage.exception.MyException; |
|||
import com.dreamchaser.depository_manage.service.impl.EPSON.ENS.ENSWrapperImpl; |
|||
|
|||
|
|||
public class MessageString { |
|||
public static final int STATE_ENS_ERROR = 1; |
|||
public static final int STATE_MEDIA_LAYOUT_ERROR = 2; |
|||
public static final int STATE_MEDIA_POSITION_ERROR = 3; |
|||
public static final int STATE_PRINT_SETTING_ERROR = 4; |
|||
public static final int STATE_EPDI_DLL_NOT_FOUND = 5; |
|||
public static final int STATE_ENS_DLL_NOT_FOUND = 6; |
|||
public static final int STATE_DRIVER_NOT_FOUND = 7; |
|||
public static final int STATE_SYSTEM_PARAM_ERROR = 8; |
|||
public static final int STATE_DRAWIMAGE_ERROR = 9; |
|||
|
|||
public static final String STR_ENS_ERROR = "Can't get the printer status.\n\nEpsonNet SDK error code : "; |
|||
public static final String STR_MEDIA_LAYOUT_ERROR = "Fail to add the media layout.\r\n\r\nEPDI error code : "; |
|||
public static final String STR_MEDIA_POSITION_ERROR = "Fail to change the media position detection setting.\r\n\r\nEPDI error code : "; |
|||
public static final String STR_PRINT_SETTING_ERROR = "Fail to change the print settings.\r\n\r\nEPDI error code : "; |
|||
public static final String STR_STATUS_BUSY = "Printer is busy.\r\nStop the printing..."; |
|||
public static final String STR_STATUS_PRINTING = "Printer is printing now.\r\nStop the printing..."; |
|||
public static final String STR_STATUS_CLEANING = "Printer is cleaning the print head.\r\nStop the printing..."; |
|||
public static final String STR_STATUS_OTHER = "Printer is busy.\r\nStop the printing..."; |
|||
public static final String STR_ERROR_PAPERJAM = "Paper jam error.\r\nStop the printing..."; |
|||
public static final String STR_ERROR_PAPEROUT = "Paper out error.\r\nStop the printing..."; |
|||
public static final String STR_ERROR_INKEND = "Ink cartridge error.\r\nStop the printing..."; |
|||
public static final String STR_ERROR_OTHER = "Other error.\r\nStop the printing..."; |
|||
public static final String STR_WARNING_INKLOW = "Ink is low.\r\n"; |
|||
public static final String STR_WARNING_OTHER = "Other warning.\r\n"; |
|||
public static final String STR_EPDI_DLL_NOT_FOUND = "doesn't support this function.\r\nOr check if program architecture(x86/x64) and OS architecture are correct."; |
|||
public static final String STR_ENS_DLL_NOT_FOUND = "EpsonNet SDK isn't installed in this PC.\r\nPerfoming the printing without printer status check."; |
|||
public static final String STR_DRIVER_NOT_FOUND = "Epson printer doesn't exist. \r\n\r\nPlease install the printer driver before starting the sample program."; |
|||
public static final String STR_SYSTEM_PARAM_ERROR = "Specified value is out of range."; |
|||
public static final String STR_DRAWIMAGE_ERROR = "Failed to print image."; |
|||
|
|||
|
|||
public static boolean GetSDKError(int i, int state) { |
|||
boolean err = true; |
|||
String strMessage = ""; |
|||
String strSDKErrorCode; |
|||
|
|||
try { |
|||
if (i != ENSEnumrations.ENSErrorCode.ERR_BASE.getI()) { |
|||
strMessage = STR_ENS_ERROR; |
|||
err = false; |
|||
ENSEnumrations.ENSErrorCode ensErrorCode = ENSEnumrations.ENSErrorCode.getENSErrorCode(i); |
|||
if (ensErrorCode != null) { |
|||
strSDKErrorCode = ensErrorCode.toString(); |
|||
} |
|||
|
|||
} |
|||
} catch (Exception e) { |
|||
// Error handling.
|
|||
throw new MyException(e.getMessage()); |
|||
} |
|||
return err; |
|||
} |
|||
|
|||
|
|||
public static boolean GetEPDMError(int i, int state) |
|||
{ |
|||
boolean err = true; |
|||
String strMessage = ""; |
|||
String strEPDMErrorCode; |
|||
|
|||
try |
|||
{ |
|||
if (i != EPDMEnumrations.EPDMErrorCode.EPDM_ERR_NORMAL.getI()) |
|||
{ |
|||
switch(state) |
|||
{ |
|||
case (STATE_MEDIA_LAYOUT_ERROR): |
|||
{ |
|||
strMessage = STR_MEDIA_LAYOUT_ERROR; |
|||
err = false; |
|||
break; |
|||
} |
|||
case (STATE_MEDIA_POSITION_ERROR): |
|||
{ |
|||
strMessage = STR_MEDIA_POSITION_ERROR; |
|||
err = false; |
|||
break; |
|||
} |
|||
case (STATE_PRINT_SETTING_ERROR): |
|||
{ |
|||
strMessage = STR_PRINT_SETTING_ERROR; |
|||
err = false; |
|||
break; |
|||
} |
|||
default: |
|||
{ |
|||
strMessage = ""; |
|||
err = false; |
|||
break; |
|||
} |
|||
} |
|||
if (strMessage.length() > 0) |
|||
{ |
|||
strEPDMErrorCode = EPDMEnumrations.EPDMErrorCode.valueOf(strMessage).toString(); |
|||
} |
|||
} |
|||
} |
|||
catch (Exception e) |
|||
{ |
|||
// Error handling.
|
|||
} |
|||
return err; |
|||
} |
|||
|
|||
|
|||
public static boolean GetPrinterStatusError(ENSEnumrations.StatusCode sc, ENSEnumrations.ErrorCode ec, ENSWrapperImpl.WARNING_INFO wc) |
|||
{ |
|||
boolean err = true; |
|||
String strMessage = ""; |
|||
|
|||
try |
|||
{ |
|||
switch (sc) |
|||
{ |
|||
case ST_Busy: |
|||
{ |
|||
strMessage = STR_STATUS_BUSY; |
|||
err = false; |
|||
break; |
|||
} |
|||
case ST_Wait: |
|||
{ |
|||
strMessage = STR_STATUS_PRINTING; |
|||
err = false; |
|||
break; |
|||
} |
|||
case ST_Cleaning: |
|||
{ |
|||
strMessage = STR_STATUS_CLEANING; |
|||
err = false; |
|||
break; |
|||
} |
|||
case ST_Error: |
|||
{ |
|||
switch (ec) |
|||
{ |
|||
case ERR_PaperJam: |
|||
{ |
|||
strMessage = STR_ERROR_PAPERJAM; |
|||
err = false; |
|||
break; |
|||
} |
|||
case ERR_Paperout: |
|||
{ |
|||
strMessage = STR_ERROR_PAPEROUT; |
|||
err = false; |
|||
break; |
|||
} |
|||
case ERR_Inkout: |
|||
{ |
|||
strMessage = STR_ERROR_INKEND; |
|||
err = false; |
|||
break; |
|||
} |
|||
default: |
|||
{ |
|||
strMessage = STR_ERROR_OTHER; |
|||
err = false; |
|||
break; |
|||
} |
|||
} |
|||
break; |
|||
} |
|||
case ST_Idle: |
|||
{ |
|||
if (wc.InkLowWarning ) |
|||
{ |
|||
strMessage += STR_WARNING_INKLOW; |
|||
err = true; |
|||
} |
|||
if (wc.OtherWarning) |
|||
{ |
|||
strMessage += STR_WARNING_OTHER; |
|||
err = true; |
|||
} |
|||
break; |
|||
} |
|||
default: |
|||
{ |
|||
strMessage = STR_STATUS_OTHER; |
|||
err = false; |
|||
break; |
|||
} |
|||
} |
|||
if (strMessage.length() > 0) |
|||
{ |
|||
// MessageBox.Show((strMessage), "", MessageBoxButtons.OK);
|
|||
// 弹出一个消息框,并返回结构
|
|||
} |
|||
} |
|||
catch (Exception e) |
|||
{ |
|||
// Error handling.
|
|||
} |
|||
return err; |
|||
} |
|||
|
|||
|
|||
public static boolean GetSystemError(int state, String devName) |
|||
{ |
|||
boolean err = true; |
|||
String strMessage = ""; |
|||
|
|||
if ( devName == null) |
|||
{ |
|||
devName = ""; |
|||
} |
|||
try |
|||
{ |
|||
switch (state) |
|||
{ |
|||
case (STATE_EPDI_DLL_NOT_FOUND): |
|||
{ |
|||
strMessage = String.format("%s %s",devName, STR_EPDI_DLL_NOT_FOUND); |
|||
err = false; |
|||
break; |
|||
} |
|||
default: |
|||
{ |
|||
strMessage = ""; |
|||
err = false; |
|||
break; |
|||
} |
|||
} |
|||
if (strMessage.length() > 0) |
|||
{ |
|||
// MessageBox.Show((strMessage), "", MessageBoxButtons.OK);
|
|||
// 弹出一个文本信息框
|
|||
} |
|||
} |
|||
catch (Exception e) |
|||
{ |
|||
// Error handling.
|
|||
} |
|||
return err; |
|||
} |
|||
|
|||
public static boolean GetSystemError(int state) |
|||
{ |
|||
boolean err = true; |
|||
String strMessage = ""; |
|||
|
|||
try |
|||
{ |
|||
switch (state) |
|||
{ |
|||
case (STATE_ENS_DLL_NOT_FOUND): |
|||
{ |
|||
strMessage = STR_ENS_DLL_NOT_FOUND; |
|||
err = false; |
|||
break; |
|||
} |
|||
case (STATE_DRIVER_NOT_FOUND): |
|||
{ |
|||
strMessage = STR_DRIVER_NOT_FOUND; |
|||
err = false; |
|||
break; |
|||
} |
|||
case (STATE_SYSTEM_PARAM_ERROR): |
|||
{ |
|||
strMessage = STR_SYSTEM_PARAM_ERROR; |
|||
err = false; |
|||
break; |
|||
} |
|||
case (STATE_DRAWIMAGE_ERROR): |
|||
{ |
|||
strMessage = STR_DRAWIMAGE_ERROR; |
|||
err = false; |
|||
break; |
|||
} |
|||
default: |
|||
{ |
|||
strMessage = ""; |
|||
err = false; |
|||
break; |
|||
} |
|||
} |
|||
if (strMessage.length() > 0) |
|||
{ |
|||
// MessageBox.Show((strMessage), "", MessageBoxButtons.OK);
|
|||
// 弹出一个文本信息框
|
|||
} |
|||
} |
|||
catch (Exception e) |
|||
{ |
|||
// Error handling.
|
|||
} |
|||
return err; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,125 @@ |
|||
package com.dreamchaser.depository_manage.EPSON.Other; |
|||
|
|||
import com.dreamchaser.depository_manage.exception.MyException; |
|||
|
|||
import javax.print.PrintService; |
|||
import java.awt.*; |
|||
import java.awt.geom.Rectangle2D; |
|||
import java.awt.print.*; |
|||
|
|||
public class Print { |
|||
private int _pageNumber = 0; |
|||
private int _totalPrintPage = 0; |
|||
private boolean _exceptionFlag = false; |
|||
|
|||
private PrinterJob _pdPrint; |
|||
|
|||
|
|||
private void PD_PrintPage() |
|||
{ |
|||
try |
|||
{ |
|||
PD_PrintPage_DrawBarcode(); |
|||
PD_PrintPage_Close(); |
|||
} |
|||
catch (Exception e) |
|||
{ |
|||
// Error handling.
|
|||
_exceptionFlag = true; |
|||
} |
|||
} |
|||
|
|||
|
|||
public Print(String devName, String portName, int totalPrintPage) |
|||
{ |
|||
try |
|||
{ |
|||
// Create the PrintDocumentObject.
|
|||
_pdPrint = PrinterJob.getPrinterJob(); |
|||
// Add the PrintPageEventHandler.
|
|||
// _pdPrint.PrintPage += new PrintPageEventHandler(PD_PrintPage);
|
|||
|
|||
// Set the using Printer.
|
|||
PrintService[] printServices = PrinterJob.lookupPrintServices(); |
|||
for (PrintService printService:printServices |
|||
) { |
|||
String name = printService.getName(); |
|||
if(name.contains(devName)){ |
|||
_pdPrint.setPrintService(printService); |
|||
break; |
|||
} |
|||
} |
|||
_pdPrint.setJobName("Test Print"); |
|||
|
|||
|
|||
_totalPrintPage = totalPrintPage; |
|||
|
|||
return; |
|||
} |
|||
catch(Exception e) |
|||
{ |
|||
// Error handling.
|
|||
throw new MyException(e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
public void DoPrinting() |
|||
{ |
|||
try |
|||
{ |
|||
// Start the print.
|
|||
_pdPrint.print(); |
|||
|
|||
if(_exceptionFlag) |
|||
{ |
|||
throw new Exception(); |
|||
} |
|||
} |
|||
catch (Exception e) |
|||
{ |
|||
// Error handling.
|
|||
throw new MyException(e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
private void PD_PrintPage_DrawBarcode() |
|||
{ |
|||
try |
|||
{ |
|||
// 调用预设二维码打印类
|
|||
_pdPrint.setPrintable(new PrintBarCode()); |
|||
} |
|||
catch (Exception e) |
|||
{ |
|||
// Error handling.
|
|||
throw new MyException(e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
private void PD_PrintPage_Close() |
|||
{ |
|||
try |
|||
{ |
|||
// Check final page.
|
|||
if (_pageNumber < _totalPrintPage) |
|||
{ |
|||
_pdPrint.cancel(); |
|||
} |
|||
|
|||
} |
|||
catch (Exception e) |
|||
{ |
|||
// Error handling.
|
|||
throw new MyException(e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
@ -0,0 +1,57 @@ |
|||
package com.dreamchaser.depository_manage.EPSON.Other; |
|||
|
|||
import java.awt.*; |
|||
import java.awt.print.PageFormat; |
|||
import java.awt.print.Printable; |
|||
import java.awt.print.PrinterException; |
|||
|
|||
public class PrintBarCode implements Printable { |
|||
|
|||
/** |
|||
|
|||
* @param graphics 指明打印的图形环境 |
|||
|
|||
* @param pageFormat 指明打印页格式(页面大小以点为计量单位,1点为1英才的1/72,1英寸为25.4毫米。A4纸大致为595×842点) |
|||
|
|||
* @param pageIndex 指明页号 |
|||
|
|||
**/ |
|||
|
|||
// 设置用于打印的编码
|
|||
public String code; |
|||
|
|||
|
|||
public void setCode(String code) { |
|||
this.code = code; |
|||
} |
|||
|
|||
@Override |
|||
public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException { |
|||
|
|||
|
|||
//print string
|
|||
String str = code; |
|||
|
|||
//转换成Graphics2D
|
|||
Graphics2D g2 = (Graphics2D) g; |
|||
|
|||
//设置打印颜色为黑色
|
|||
g2.setColor(Color.black); |
|||
|
|||
//打印起点坐标
|
|||
double x = pf.getImageableX(); |
|||
double y = pf.getImageableY(); |
|||
|
|||
if (pageIndex == 0) {//设置打印字体(字体名称、样式和点大小)(字体名称可以是物理或者逻辑名称)
|
|||
|
|||
//Java平台所定义的五种字体系列:Serif、SansSerif、Monospaced、Dialog 和 DialogInput
|
|||
Font font = new Font("Courier New", Font.PLAIN, 9); |
|||
g2.setFont(font);//设置字体
|
|||
|
|||
g2.drawString(code,20,100); |
|||
|
|||
return PAGE_EXISTS; |
|||
} |
|||
return NO_SUCH_PAGE; |
|||
} |
|||
} |
|||
@ -0,0 +1,57 @@ |
|||
package com.dreamchaser.depository_manage.EPSON.Other; |
|||
|
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.profesorfalken.wmi4java.WMI4Java; |
|||
import org.apache.catalina.Manager; |
|||
|
|||
import javax.print.PrintService; |
|||
import javax.print.attribute.PrintServiceAttributeSet; |
|||
import java.awt.*; |
|||
import java.awt.print.PrinterJob; |
|||
import java.io.PrintStream; |
|||
import java.net.InetAddress; |
|||
import java.net.Socket; |
|||
import java.util.ArrayList; |
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 用于实现打印机选择的类 |
|||
*/ |
|||
public class SelectPrinterInfo { |
|||
|
|||
public static List<PRINTER_INFO> GetPrinterInfoList() { |
|||
|
|||
//定义打印机信息列表
|
|||
List<PRINTER_INFO> printerInfoList = new ArrayList<PRINTER_INFO>(); |
|||
PRINTER_INFO printerInfo; |
|||
try { |
|||
// 获取本地所有打印机
|
|||
List<Map<String, String>> wmiObjectListProperties = WMI4Java.get().getWMIObjectList("Win32_PRINTER"); |
|||
for (Map<String,String> printer:wmiObjectListProperties |
|||
) { |
|||
|
|||
printerInfo = new PRINTER_INFO(); |
|||
// 获取设备名称
|
|||
printerInfo.devName = printer.get("Name"); |
|||
// 获取端口名称
|
|||
printerInfo.portName =printer.get("PortName") ; |
|||
|
|||
if (printerInfo.devName.contains("EPSON")){ |
|||
printerInfoList.add(printerInfo); |
|||
} |
|||
|
|||
} |
|||
return printerInfoList; |
|||
} catch (Exception e) { |
|||
System.out.println(e.getMessage()); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
public static class PRINTER_INFO { |
|||
public String devName; |
|||
public String portName; |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
package com.dreamchaser.depository_manage.EPSON.epsonException; |
|||
|
|||
import com.dreamchaser.depository_manage.EPSON.ENS.ENSEnumrations; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
|
|||
/** |
|||
* 用于ENS的错误类 |
|||
*/ |
|||
@EqualsAndHashCode(callSuper = true) |
|||
@Data |
|||
public class ENSException extends Exception{ |
|||
|
|||
private static final long serialVersionUID = -2429062150745133718L; |
|||
|
|||
/** |
|||
* 错误类型 |
|||
*/ |
|||
public ENSEnumrations.ENSErrorCode ensErrorCode; |
|||
|
|||
|
|||
public ENSEnumrations.ENSErrorCode getEnsErrorCode() { |
|||
return ensErrorCode; |
|||
} |
|||
|
|||
public void setEnsErrorCode(ENSEnumrations.ENSErrorCode ensErrorCode) { |
|||
this.ensErrorCode = ensErrorCode; |
|||
} |
|||
|
|||
public ENSException(ENSEnumrations.ENSErrorCode e) |
|||
{ |
|||
ensErrorCode = e; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
package com.dreamchaser.depository_manage.EPSON.epsonException; |
|||
|
|||
import com.dreamchaser.depository_manage.EPSON.EPDM.EPDMEnumrations; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
|
|||
/** |
|||
* 用于EPDM的错误类 |
|||
*/ |
|||
@EqualsAndHashCode(callSuper = true) |
|||
@Data |
|||
public class EPDMException extends Exception { |
|||
|
|||
private static final long serialVersionUID = 6037874212969710082L; |
|||
|
|||
/** |
|||
* 错误类型 |
|||
*/ |
|||
public EPDMEnumrations.EPDMErrorCode epdmErrorCode; |
|||
|
|||
public EPDMException(EPDMEnumrations.EPDMErrorCode e) |
|||
{ |
|||
epdmErrorCode = e; |
|||
} |
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
package com.dreamchaser.depository_manage.aop; |
|||
|
|||
import org.aspectj.lang.JoinPoint; |
|||
import org.aspectj.lang.annotation.Aspect; |
|||
import org.aspectj.lang.annotation.Before; |
|||
import org.aspectj.lang.annotation.Pointcut; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.stereotype.Component; |
|||
import org.springframework.web.context.request.RequestAttributes; |
|||
import org.springframework.web.context.request.RequestContextHolder; |
|||
import org.springframework.web.context.request.ServletRequestAttributes; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import java.util.Arrays; |
|||
|
|||
/** |
|||
* 日志切面 |
|||
*/ |
|||
@Aspect |
|||
@Component |
|||
public class WebLogAspect { |
|||
private final Logger logger = LoggerFactory.getLogger(WebLogAspect.class); |
|||
|
|||
@Pointcut("execution(public * com.dreamchaser.depository_manage.controller..*.*(..))")//切入点描述 这个是controller包的切入点
|
|||
public void controllerLog(){}//签名,可以理解成这个切入点的一个名称
|
|||
|
|||
|
|||
public void logBeforeController(JoinPoint joinPoint) { |
|||
//这个RequestContextHolder是Springmvc提供来获得请求的东西
|
|||
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); |
|||
HttpServletRequest request = ((ServletRequestAttributes)requestAttributes).getRequest(); |
|||
|
|||
// 记录下请求内容
|
|||
logger.info("################URL : " + request.getRequestURL().toString()); |
|||
logger.info("################HTTP_METHOD : " + request.getMethod()); |
|||
logger.info("################IP : " + request.getRemoteAddr()); |
|||
logger.info("################THE ARGS OF THE CONTROLLER : " + Arrays.toString(joinPoint.getArgs())); |
|||
|
|||
//下面这个getSignature().getDeclaringTypeName()是获取包+类名的 然后后面的joinPoint.getSignature.getName()获取了方法名
|
|||
logger.info("################CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName()); |
|||
//logger.info("################TARGET: " + joinPoint.getTarget());//返回的是需要加强的目标类的对象
|
|||
//logger.info("################THIS: " + joinPoint.getThis());//返回的是经过加强后的代理类的对象
|
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
package com.dreamchaser.depository_manage.config.EPSON.ENS; |
|||
|
|||
import com.dreamchaser.depository_manage.EPSON.ENS.ENSStatus; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
public class Global_MEDIA_ENS { |
|||
|
|||
/** |
|||
* 用于全局INKSIDMSTATUS_02中的实现 |
|||
*/ |
|||
public static Map<Integer, ENSStatus.INKSIDMSTATUS_02> integerINKSIDMSTATUS_02Map = new HashMap<>(); |
|||
|
|||
|
|||
/** |
|||
* 用于存储ENS中出现要进行暂存的字符串 |
|||
*/ |
|||
public static Map<Integer,String> ENS_STRUCTURE_Str = new HashMap<>(); |
|||
} |
|||
@ -0,0 +1,77 @@ |
|||
package com.dreamchaser.depository_manage.config.EPSON.EPDM; |
|||
|
|||
|
|||
import com.dreamchaser.depository_manage.EPSON.EPDM.EPDMMediaLayoutRange; |
|||
import com.dreamchaser.depository_manage.EPSON.EPDM.EPDMMediaTypeRange; |
|||
import com.dreamchaser.depository_manage.EPSON.EPDM.EPDMSelectData; |
|||
import com.dreamchaser.depository_manage.EPSON.EPDM.EPDMString; |
|||
import com.dreamchaser.depository_manage.entity.EPSON.EPDM.EPDMMediaLayoutInf; |
|||
import com.dreamchaser.depository_manage.entity.EPSON.EPDM.MEDIA_LAYOUT_RANGE; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
public class Global_MEDIA_EPDM { |
|||
/** |
|||
* 用于全局MEDIA_LAYOUT_RANGE中的实现 |
|||
*/ |
|||
public static Map<Integer,MEDIA_LAYOUT_RANGE> media_layout_rangeMap = new HashMap<>(); |
|||
|
|||
/** |
|||
* 用于全局EPDMMediaLayoutRange的实现 |
|||
*/ |
|||
public static Map<Integer,EPDMMediaLayoutRange> epdmMediaLayoutRangeMap = new HashMap<>(); |
|||
|
|||
|
|||
/** |
|||
* 用于全局EPDM_MEDIALAYOUTRANGE的实现 |
|||
*/ |
|||
public static Map<Integer, EPDMMediaLayoutRange.EPDM_MEDIALAYOUTRANGE> epdm_medialayoutrangeMap = new HashMap<>(); |
|||
|
|||
|
|||
/** |
|||
* |
|||
* 用于全局EPDM_MEDIATYPERANGE的实现 |
|||
*/ |
|||
public static Map<Integer, EPDMMediaTypeRange.EPDM_MEDIATYPERANGE> epdm_mediatyperangeMap = new HashMap<>(); |
|||
|
|||
|
|||
/** |
|||
* 用于全局EPDM_SELECTDATA的实现 |
|||
*/ |
|||
public static Map<Integer, EPDMSelectData.EPDM_SELECTDATA> epdm_selectdataMap = new HashMap<>(); |
|||
|
|||
/** |
|||
* 用于EPDMMediaLayoutRange中的PtrToStructure转short |
|||
*/ |
|||
public static Map<Integer,Short> epdm_mediaLayoutRange_short = new HashMap<>(); |
|||
|
|||
/** |
|||
* 用于全局EPDM_STRING_1的实现 |
|||
*/ |
|||
public static Map<Integer, EPDMString.EPDM_STRING_1> epdm_string_1Map = new HashMap<>(); |
|||
|
|||
|
|||
/** |
|||
* 用于EPDMSelectData中的使用 |
|||
*/ |
|||
public static List<Long> epdm_select_data_int64 = new ArrayList<>(); |
|||
public static List<Integer> epdm_select_data_int32 = new ArrayList<>(); |
|||
public static List<Short> epdm_select_data_int16 = new ArrayList<>(); |
|||
|
|||
|
|||
/** |
|||
* 用于EPDMString中使用的byte |
|||
*/ |
|||
public static Map<Integer,Byte> epdm_epdmString_byte = new HashMap<>(); |
|||
|
|||
|
|||
/** |
|||
* 用于全局EPDM_MEDIALAYOUTINF的实现 |
|||
*/ |
|||
public static Map<Integer, EPDMMediaLayoutInf.EPDM_MEDIALAYOUTINF> epdm_medialayoutinfMap = new HashMap<>(); |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
package com.dreamchaser.depository_manage.config; |
|||
|
|||
import lombok.Data; |
|||
import org.springframework.boot.context.properties.ConfigurationProperties; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
/** |
|||
* 用于文件上传时的路径存储 |
|||
*/ |
|||
@Data |
|||
@Component |
|||
@ConfigurationProperties(prefix = "file") |
|||
public class FileConfig { |
|||
|
|||
// 上传路径
|
|||
private String uploadPath; |
|||
|
|||
} |
|||
@ -0,0 +1,76 @@ |
|||
package com.dreamchaser.depository_manage.config; |
|||
|
|||
import org.apache.commons.codec.digest.DigestUtils; |
|||
import javax.crypto.Cipher; |
|||
import javax.crypto.SecretKey; |
|||
import javax.crypto.spec.SecretKeySpec; |
|||
import java.util.Base64; |
|||
|
|||
|
|||
/** |
|||
* 用于3DES加密解密 |
|||
*/ |
|||
public class JM_3DES { |
|||
|
|||
public static String JM_Key = "scanQrCode"; |
|||
/** |
|||
* 获取key |
|||
* @param key |
|||
* @return |
|||
*/ |
|||
public static byte[] hex(String key){ |
|||
String f = DigestUtils.md5Hex(key); |
|||
byte[] bkeys = new String(f).getBytes(); |
|||
byte[] enk = new byte[24]; |
|||
for (int i=0;i<24;i++){ |
|||
enk[i] = bkeys[i]; |
|||
} |
|||
return enk; |
|||
} |
|||
|
|||
/** |
|||
* 3DES加密 |
|||
* @param key 密钥 |
|||
* @param srcStr 需要加密的字符串 |
|||
* @return |
|||
*/ |
|||
public static String encode3Des(String key, String srcStr){ |
|||
byte[] keybyte = hex(key); |
|||
byte[] src = srcStr.getBytes(); |
|||
try { |
|||
//生成密钥
|
|||
SecretKey deskey = new SecretKeySpec(keybyte, "DESede"); |
|||
//加密
|
|||
Cipher c1 = Cipher.getInstance("DESede"); |
|||
c1.init(Cipher.ENCRYPT_MODE, deskey); |
|||
String pwd = Base64.getEncoder().encodeToString(c1.doFinal(src)); |
|||
return pwd; |
|||
}catch(Exception e){ |
|||
e.printStackTrace(); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
/** |
|||
* 3DES解密 |
|||
* @param key 加密密钥 |
|||
* @param desStr 需要解密的字符串 |
|||
* @return |
|||
*/ |
|||
public static String decode3Des(String key, String desStr){ |
|||
byte[] keybyte = hex(key); |
|||
try { |
|||
byte[] src = Base64.getDecoder().decode(desStr); |
|||
//生成密钥
|
|||
SecretKey deskey = new SecretKeySpec(keybyte, "DESede"); |
|||
//解密
|
|||
Cipher c1 = Cipher.getInstance("DESede"); |
|||
c1.init(Cipher.DECRYPT_MODE, deskey); |
|||
String pwd = new String(c1.doFinal(src)); |
|||
return pwd; |
|||
}catch(Exception e){ |
|||
e.printStackTrace(); |
|||
} |
|||
return null; |
|||
} |
|||
} |
|||
@ -0,0 +1,594 @@ |
|||
package com.dreamchaser.depository_manage.config; |
|||
|
|||
import com.alibaba.fastjson.JSON; |
|||
import com.alibaba.fastjson.JSONArray; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.dreamchaser.depository_manage.entity.Administration; |
|||
import com.dreamchaser.depository_manage.entity.Post; |
|||
import com.dreamchaser.depository_manage.entity.UserByPort; |
|||
import com.dreamchaser.depository_manage.pojo.AdministrationP; |
|||
import com.dreamchaser.depository_manage.utils.HttpUtils; |
|||
import com.dreamchaser.depository_manage.utils.ObjectFormatUtil; |
|||
import lombok.Data; |
|||
import org.apache.http.protocol.HTTP; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import java.io.IOException; |
|||
import java.util.*; |
|||
import java.util.concurrent.ExecutorService; |
|||
import java.util.concurrent.TimeUnit; |
|||
|
|||
/** |
|||
* 用于对接HR系统 |
|||
*/ |
|||
@Data |
|||
public class PublicConfig { |
|||
// 部署数据库 depository NhE47edekBHxhjYk
|
|||
|
|||
|
|||
// 接口地址(本地使用,外网使用)
|
|||
public static String external_url = "http://172.20.2.87:39168"; |
|||
// 部署后,内网使用
|
|||
// public static String external_url = "http://127.0.0.1:39168";
|
|||
public static String external_url_6666 = "http://kpi.hxgk.group/kpiapi"; |
|||
|
|||
// 外网地址,用于接收验证
|
|||
public static String external_url_extranet = "http://172.20.2.87:7777"; |
|||
|
|||
|
|||
|
|||
// 高权限部门列表(仓储中心,企管部,综合办)
|
|||
/** |
|||
* 因为后需要进行整合,暂没进行具体权限分配,暂用部门进行分配 |
|||
*/ |
|||
public static List<Long> roleAdminorgList = Arrays.asList(361L, 102L, 268L); |
|||
|
|||
// 定义登录存储在redis中的前缀
|
|||
public static String LoginRedisPrefix = "HXGK_GO_ZhixingCollege:ScanCode:Authentication:LoginApi_dev_"; |
|||
// 定义存储在redis中的用户信息
|
|||
public static String userInfoRedisPrefix = "HXGK_GO_ZhixingCollege:ScanCode:Authentication:UserCont_dev_"; |
|||
// 定义redis加锁的名称
|
|||
public static String redis_Lock_name = "Wms_redis_lock"; |
|||
|
|||
/** |
|||
* 当前电脑可用的空闲cpu |
|||
*/ |
|||
public static int availableVirtualMachine = Runtime.getRuntime().availableProcessors(); |
|||
|
|||
/** |
|||
* 获取相应部门的部门负责人 |
|||
* |
|||
* @param userToken 待获取人员 |
|||
* @return |
|||
*/ |
|||
public static List<UserByPort> findDepartmentHeadByUser(Long maindeparment, String userKey, String userToken) { |
|||
List<UserByPort> userByPortList = new ArrayList<>(); |
|||
if (Long.compare(maindeparment, 361) == 0) { |
|||
// 如果申请人部门为仓储
|
|||
UserByPort userByPort = FindUserById(119L, userKey, userToken); |
|||
userByPortList.add(userByPort); |
|||
return userByPortList; |
|||
} |
|||
if (Long.compare(maindeparment, 111) == 0) { |
|||
// 如果申请人部门为仓储
|
|||
UserByPort userByPort = FindUserById(3604L, userKey, userToken); |
|||
userByPortList.add(userByPort); |
|||
return userByPortList; |
|||
} |
|||
String url = PublicConfig.external_url + "/staff/archiveslist"; |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("adminorg", maindeparment); |
|||
map.put("role", ""); |
|||
String jsonString = JSONObject.toJSONString(map); |
|||
JSONObject paramObject = JSONObject.parseObject(jsonString); |
|||
String post = null; |
|||
try { |
|||
post = HttpUtils.send(url, paramObject, HTTP.UTF_8, userKey, userToken); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
JSONObject jsonObject = JSONObject.parseObject(post); |
|||
JSONObject data = (JSONObject) jsonObject.get("data"); |
|||
JSONArray list = (JSONArray) data.get("list"); |
|||
if (list == null) { |
|||
list = new JSONArray(); |
|||
} |
|||
|
|||
for (Object obj : list |
|||
) { |
|||
JSONObject jsonObject1 = (JSONObject) obj; |
|||
int personincharge = jsonObject1.getInteger("personincharge"); |
|||
if (1 == personincharge) { |
|||
userByPortList.add(JSONObject.toJavaObject(jsonObject1, UserByPort.class)); |
|||
} |
|||
} |
|||
return userByPortList; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 获取当前部门下的对应职位的下的人员 |
|||
* |
|||
* @param maindepartment 查询部门 |
|||
* @param positionName 查询职位 |
|||
* @return |
|||
*/ |
|||
public static List<UserByPort> findUserByAdminorgAndPosition(Long maindepartment, String positionName, String userKey, String userToken) { |
|||
List<UserByPort> userByPortList = new ArrayList<>(); |
|||
String url = PublicConfig.external_url + "/org/positionlist"; |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("organization", maindepartment.toString()); |
|||
map.put("name", positionName); |
|||
String jsonString = JSONObject.toJSONString(map); |
|||
JSONObject paramObject = JSONObject.parseObject(jsonString); |
|||
String post = null; |
|||
try { |
|||
post = HttpUtils.send(url, paramObject, HTTP.UTF_8, userKey, userToken); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
JSONObject jsonObject = JSONObject.parseObject(post); |
|||
JSONObject data = (JSONObject) jsonObject.get("data"); |
|||
JSONArray list = (JSONArray) data.get("list"); |
|||
if (list == null) { |
|||
list = new JSONArray(); |
|||
} |
|||
// 定义获取的岗位
|
|||
Post position = null; |
|||
for (Object o : list) { |
|||
position = JSONObject.toJavaObject((JSONObject) o, Post.class); |
|||
} |
|||
|
|||
// 获取当前部门下的所有人员
|
|||
if (position != null) { |
|||
List<UserByPort> allUserByMainDepartment = FindUserByAdminorg(maindepartment, userKey, userToken); |
|||
for (UserByPort userByPort : allUserByMainDepartment) { |
|||
int emptype = userByPort.getEmptype(); |
|||
if (emptype > 10) { |
|||
continue; |
|||
} |
|||
if (Long.compare(userByPort.getPosition(), position.getId()) == 0) { |
|||
userByPortList.add(userByPort); |
|||
} |
|||
|
|||
} |
|||
} |
|||
return userByPortList; |
|||
} |
|||
|
|||
// 通过获取的企业微信UserId获取数据库中的用户以及对应key与token
|
|||
public static Map<String, Object> findUserByQyWxUserId(String userId) { |
|||
String url = external_url + "/staff/wechat_give_uscont"; |
|||
Map<String, Object> result = new HashMap<>(); |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("openid", userId); |
|||
String jsonString = JSONObject.toJSONString(map); |
|||
JSONObject paramObject = JSONObject.parseObject(jsonString); |
|||
String post = null; |
|||
try { |
|||
post = HttpUtils.send(url, paramObject, HTTP.UTF_8, null, null); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
JSONObject jsonObject = JSONObject.parseObject(post); |
|||
JSONObject data = (JSONObject) jsonObject.get("data"); |
|||
UserByPort userByPort = JSONObject.toJavaObject((JSONObject) data.get("userinfo"), UserByPort.class); |
|||
String userKey = data.getString("key"); |
|||
String userToken = data.getString("token"); |
|||
result.put("key", userKey); |
|||
result.put("token", userToken); |
|||
result.put("user", userByPort); |
|||
return result; |
|||
} |
|||
|
|||
|
|||
// 修改员工微信或企业微信UserId
|
|||
public static void editUserWechatOpenid(Map<String, String> map, String userKey, String userToken) { |
|||
String url = external_url + "/staff/edit_us_wechat_openid"; |
|||
String jsonString = JSONObject.toJSONString(map); |
|||
JSONObject paramObject = JSONObject.parseObject(jsonString); |
|||
String post = null; |
|||
try { |
|||
post = HttpUtils.send(url, paramObject, HTTP.UTF_8, userKey, userToken); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
|
|||
// 获取当前登录用户所在部门的企业微信id
|
|||
public static JSONObject getUserPortByQyWx(Long mainPortId) { |
|||
String url = external_url + "/org/getgovcont"; |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("id", mainPortId); |
|||
map.put("idstr", String.valueOf(mainPortId)); |
|||
String jsonString = JSONObject.toJSONString(map); |
|||
String s = HttpUtils.doPost(url, jsonString); |
|||
JSONObject jsonObject = JSONObject.parseObject(s); |
|||
JSONObject data = jsonObject.getJSONObject("data"); |
|||
return data; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 通过工号获取用户 |
|||
* |
|||
* @param number 工号 |
|||
* @return |
|||
*/ |
|||
public static UserByPort findUserByPortByNumber(String number) { |
|||
String url = PublicConfig.external_url + "/staff/archiveslist"; |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("number", number); |
|||
String jsonString = JSONObject.toJSONString(map); |
|||
String s = HttpUtils.doPost(url, jsonString); |
|||
JSONObject jsonObject = JSONObject.parseObject(s); |
|||
JSONObject data = jsonObject.getJSONObject("data"); |
|||
JSONArray list = data.getJSONArray("list"); |
|||
UserByPort userByPort = null; |
|||
for (Object o : list) { |
|||
userByPort = JSONObject.toJavaObject((JSON) o, UserByPort.class); |
|||
if (userByPort != null) { |
|||
break; |
|||
} |
|||
} |
|||
return userByPort; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于关闭线程池 |
|||
* |
|||
* @param exs 待关闭的线程池 |
|||
*/ |
|||
public static void closeThreadPool(ExecutorService exs) { |
|||
exs.shutdown(); // 禁止提交新任务
|
|||
// 设定最大重试次数
|
|||
try { |
|||
// 等待 60 s
|
|||
if (!exs.awaitTermination(60, TimeUnit.SECONDS)) { |
|||
// 调用 shutdownNow 取消正在执行的任务
|
|||
exs.shutdownNow(); |
|||
// 再次等待 60 s,如果还未结束,可以再次尝试,或者直接放弃
|
|||
if (!exs.awaitTermination(60, TimeUnit.SECONDS)) |
|||
System.err.println("线程池任务未正常执行结束"); |
|||
} |
|||
} catch (InterruptedException ie) { |
|||
// 重新调用 shutdownNow
|
|||
exs.shutdownNow(); |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于获取Map<String,String> |
|||
* |
|||
* @param jsonObject |
|||
* @return |
|||
*/ |
|||
public static Map<String, String> returnMapString(JSONObject jsonObject) { |
|||
Map<String, String> stringObjectMap = new HashMap<>(); |
|||
for (String next : jsonObject.keySet()) { |
|||
String value = String.valueOf(jsonObject.get(next)); |
|||
stringObjectMap.put(next, value); |
|||
} |
|||
return stringObjectMap; |
|||
} |
|||
|
|||
/** |
|||
* 根据条件查询用户 |
|||
* |
|||
* @param map 条件 |
|||
* @param userToken 当前登录用户 |
|||
* @return 查询结果 |
|||
*/ |
|||
public static List<UserByPort> FindUserByMap(Map<String, Object> map, String userKey, String userToken) { |
|||
String url = external_url + "/staff/archiveslist"; |
|||
String jsonString = JSONObject.toJSONString(map); |
|||
JSONObject paramObject = JSONObject.parseObject(jsonString); |
|||
String post = null; |
|||
try { |
|||
post = HttpUtils.send(url, paramObject, HTTP.UTF_8, userKey, userToken); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
JSONObject jsonObject = JSONObject.parseObject(post); |
|||
JSONObject data = (JSONObject) jsonObject.get("data"); |
|||
JSONArray list = (JSONArray) data.get("list"); |
|||
List<UserByPort> result = new ArrayList<>(); |
|||
if (list == null) { |
|||
list = new JSONArray(); |
|||
} |
|||
for (Object o : list) { |
|||
UserByPort userByPort = JSONObject.toJavaObject((JSONObject) o, UserByPort.class); |
|||
result.add(userByPort); |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 根据用户id查询对应用户 |
|||
* |
|||
* @param id 待查讯用户id |
|||
* @param userToken 登录用户 |
|||
* @return 查询结果 |
|||
*/ |
|||
public static UserByPort FindUserById(Long id, String userKey, String userToken) { |
|||
String url = external_url + "/staff/archivescont"; |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("id", id); |
|||
String jsonString = JSONObject.toJSONString(map); |
|||
JSONObject paramObject = JSONObject.parseObject(jsonString); |
|||
String post = null; |
|||
try { |
|||
post = HttpUtils.send(url, paramObject, HTTP.UTF_8, userKey, userToken); |
|||
|
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
JSONObject jsonObject = JSONObject.parseObject(post); |
|||
JSONObject data = (JSONObject) jsonObject.get("data"); |
|||
UserByPort userByPort = JSONObject.toJavaObject(data, UserByPort.class); |
|||
if ("300732".equals(userByPort.getNumber())) { |
|||
userByPort.setMaindeparment(361L); |
|||
userByPort.setMaindeparmentname("仓储中心"); |
|||
} |
|||
|
|||
return userByPort; |
|||
} |
|||
|
|||
/** |
|||
* 查询当前部门下的用户 |
|||
* |
|||
* @param id 待查讯部门id |
|||
* @param userToken 登录用户 |
|||
* @return 查询结果 |
|||
*/ |
|||
public static List<UserByPort> FindUserByAdminorg(Long id, String userKey, String userToken) { |
|||
String url = external_url + "/staff/archiveslist"; |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("adminorg", id); |
|||
String jsonString = JSONObject.toJSONString(map); |
|||
JSONObject paramObject = JSONObject.parseObject(jsonString); |
|||
String post = null; |
|||
try { |
|||
post = HttpUtils.send(url, paramObject, HTTP.UTF_8, userKey, userToken); |
|||
|
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
JSONObject jsonObject = JSONObject.parseObject(post); |
|||
JSONObject data = jsonObject.getJSONObject("data"); |
|||
JSONArray jsonArray = data.getJSONArray("list"); |
|||
List<UserByPort> list = new ArrayList<>(); |
|||
for (Object o : jsonArray |
|||
) { |
|||
UserByPort userByPort = JSONObject.toJavaObject((JSONObject) o, UserByPort.class); |
|||
list.add(userByPort); |
|||
|
|||
} |
|||
return list; |
|||
} |
|||
|
|||
/** |
|||
* 根据id查询对应的行政组织 |
|||
* |
|||
* @param id 待查讯组织id |
|||
* @param |
|||
* @return 查询结果 |
|||
*/ |
|||
public static Administration getCompany(Long id, String userKey, String userToken) { |
|||
String url = external_url + "/org/getgovcont"; |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("id", id); |
|||
map.put("idstr", id.toString()); |
|||
String jsonString = JSONObject.toJSONString(map); |
|||
JSONObject paramObject = JSONObject.parseObject(jsonString); |
|||
String post = null; |
|||
try { |
|||
post = HttpUtils.send(url, paramObject, HTTP.UTF_8, userKey, userToken); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
JSONObject jsonObject = JSONObject.parseObject(post); |
|||
JSONObject data = (JSONObject) jsonObject.get("data"); |
|||
return JSONObject.toJavaObject(data, Administration.class); |
|||
} |
|||
|
|||
/** |
|||
* 根据上级查询对应的行政组织 |
|||
* |
|||
* @param superior 上级编号 |
|||
* @param |
|||
* @return 查询结果 |
|||
*/ |
|||
public static List<AdministrationP> findCompanyBySuperior(String superior, String userKey, String userToken) { |
|||
String url = external_url + "/org/govthree"; |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("idstr", superior); |
|||
map.put("level", 0); |
|||
map.put("all", 1); |
|||
String jsonString = JSONObject.toJSONString(map); |
|||
JSONObject paramObject = JSONObject.parseObject(jsonString); |
|||
String post = null; |
|||
try { |
|||
post = HttpUtils.send(url, paramObject, HTTP.UTF_8, userKey, userToken); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
JSONObject jsonObject = JSONObject.parseObject(post); |
|||
JSONArray list = (JSONArray) jsonObject.get("data"); |
|||
if (list == null) { |
|||
list = new JSONArray(); |
|||
} |
|||
List<AdministrationP> administrationPList = new ArrayList<>(); |
|||
for (Object o : list) { |
|||
Administration administration = JSONObject.toJavaObject((JSONObject) o, Administration.class); |
|||
AdministrationP administrationP = new AdministrationP(administration); |
|||
administrationPList.add(administrationP); |
|||
} |
|||
return administrationPList; |
|||
} |
|||
|
|||
/** |
|||
* 获取对应的验证码信息 |
|||
* |
|||
* @param request 请求体 |
|||
* @return 结果 |
|||
*/ |
|||
public static JSONObject Captcha(HttpServletRequest request) { |
|||
String token = request.getHeader("user-token"); |
|||
String userKey = request.getHeader("user-key"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
userKey = (String) request.getSession().getAttribute("userKey"); |
|||
} |
|||
String url = external_url_6666 + "/base/captcha"; |
|||
JSONObject param = new JSONObject(); |
|||
String post = null; |
|||
try { |
|||
post = HttpUtils.send(url, param, HTTP.UTF_8, userKey, token); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
JSONObject jsonObject = JSONObject.parseObject(post); |
|||
JSONObject data = (JSONObject) jsonObject.get("data"); |
|||
return data; |
|||
} |
|||
|
|||
/** |
|||
* 获取当前行政组织列表 |
|||
* |
|||
* @return |
|||
*/ |
|||
public static Map<String, Object> findAdministration(String userKey, String userToken) { |
|||
Map<String, Object> map = new HashMap<>(); |
|||
String url = external_url + "/org/govlist"; |
|||
String superior = "313"; |
|||
map.put("superior", superior); |
|||
map.put("state", 1); |
|||
map.put("level", 3); |
|||
String jsonString = JSONObject.toJSONString(map); |
|||
JSONObject paramObject = JSONObject.parseObject(jsonString); |
|||
String post = null; |
|||
try { |
|||
post = HttpUtils.send(url, paramObject, HTTP.UTF_8, userKey, userToken); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
JSONObject jsonObject = JSONObject.parseObject(post); |
|||
JSONObject data = (JSONObject) jsonObject.get("data"); |
|||
JSONArray list = (JSONArray) data.get("list"); |
|||
if (list == null) { |
|||
list = new JSONArray(); |
|||
} |
|||
Integer total = ObjectFormatUtil.toInteger(data.get("total")); |
|||
Map<String, Object> result = new HashMap(); |
|||
List<AdministrationP> administrationPList = new ArrayList<>(); |
|||
for (Object o : list) { |
|||
Administration administration = JSONObject.toJavaObject((JSONObject) o, Administration.class); |
|||
AdministrationP administrationP = new AdministrationP(administration); |
|||
administrationPList.add(administrationP); |
|||
} |
|||
result.put("administrationPList", administrationPList); |
|||
result.put("total", total); |
|||
return result; |
|||
} |
|||
|
|||
/** |
|||
* 用于获取行政组织树 |
|||
* |
|||
* @param userByPort |
|||
* @return |
|||
*/ |
|||
public static JSONArray getPostTree(UserByPort userByPort, String userKey, String userToken) { |
|||
String url = external_url + "/org/govthreeing"; |
|||
Map<String, Object> param = new HashMap<>(); |
|||
param.put("id", userByPort.getCompany()); |
|||
param.put("idstr", ""); |
|||
param.put("level", 0); |
|||
param.put("all", 1); |
|||
String jsonString = JSONObject.toJSONString(param); |
|||
JSONObject paramObject = JSONObject.parseObject(jsonString); |
|||
String post = null; |
|||
try { |
|||
post = HttpUtils.send(url, paramObject, HTTP.UTF_8, userKey, userToken); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
JSONObject jsonObject = JSONObject.parseObject(post); |
|||
return (JSONArray) jsonObject.get("data"); |
|||
|
|||
} |
|||
|
|||
/** |
|||
* 获取当前用户可见的菜单集 |
|||
* |
|||
* @param userToken 当前登录用户 |
|||
* @return |
|||
*/ |
|||
public static List<String> getUserAccessToAddresses(String userKey, String userToken) { |
|||
//定义链接地址
|
|||
String url = external_url_6666 + "/system_authorizing/obtain_authorization"; |
|||
System.out.println(url); |
|||
Map<String, Object> param = new HashMap<>(); |
|||
param.put("system", "cangchu"); |
|||
String jsonString = JSONObject.toJSONString(param); |
|||
JSONObject paramObject = JSONObject.parseObject(jsonString); |
|||
String post = null; |
|||
try { |
|||
post = HttpUtils.send(url, paramObject, HTTP.UTF_8, userKey, userToken); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
JSONObject jsonObject = JSONObject.parseObject(post); |
|||
JSONObject data = (JSONObject) jsonObject.get("data"); |
|||
JSONArray powerid = (JSONArray) data.get("powerid"); |
|||
if (powerid == null) { |
|||
powerid = new JSONArray(); |
|||
} |
|||
List<String> stringList = JSONObject.parseArray(powerid.toJSONString(), String.class); |
|||
return stringList; |
|||
} |
|||
|
|||
public static JSONArray getOrgAndPostThree(String userKey, String userToken) { |
|||
//定义链接地址
|
|||
String url = external_url + "/org/get_organdpost_three"; |
|||
Map<String, Object> param = new HashMap<>(); |
|||
param.put("id", "309"); |
|||
param.put("level", 0); |
|||
param.put("all", 0); |
|||
String jsonString = JSONObject.toJSONString(param); |
|||
JSONObject paramObject = JSONObject.parseObject(jsonString); |
|||
String post = null; |
|||
try { |
|||
post = HttpUtils.send(url, paramObject, HTTP.UTF_8, userKey, userToken); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
JSONObject jsonObject = JSONObject.parseObject(post); |
|||
JSONObject data = (JSONObject) jsonObject.get("data"); |
|||
return data.getJSONArray("list"); |
|||
} |
|||
|
|||
/** |
|||
* 绩效考核系统的登录接口 |
|||
* |
|||
* @param map |
|||
* @return |
|||
*/ |
|||
public static JSONObject baseLogin(Map<String, String> map) { |
|||
String url = PublicConfig.external_url_6666 + "/base/login"; |
|||
String jsonString = JSONObject.toJSONString(map); |
|||
JSONObject paramObject = JSONObject.parseObject(jsonString); |
|||
String post = null; |
|||
try { |
|||
post = HttpUtils.send(url, paramObject, HTTP.UTF_8, null, null); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
JSONObject jsonObject = JSONObject.parseObject(post); |
|||
JSONObject data = (JSONObject) jsonObject.get("data"); |
|||
return data; |
|||
} |
|||
} |
|||
@ -0,0 +1,302 @@ |
|||
package com.dreamchaser.depository_manage.config; |
|||
|
|||
|
|||
import com.alibaba.fastjson.JSON; |
|||
import com.alibaba.fastjson.JSONArray; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.dreamchaser.depository_manage.config.QyWx_template_card.*; |
|||
import com.dreamchaser.depository_manage.entity.UserByPort; |
|||
import com.dreamchaser.depository_manage.entity.qywxDepartment; |
|||
import com.dreamchaser.depository_manage.entity.qywxLabel; |
|||
import com.dreamchaser.depository_manage.entity.qywxLabelUser; |
|||
import com.dreamchaser.depository_manage.exception.MyException; |
|||
import com.dreamchaser.depository_manage.security.pool.RedisPool; |
|||
import com.dreamchaser.depository_manage.utils.HttpUtils; |
|||
import com.dreamchaser.depository_manage.utils.ObjectFormatUtil; |
|||
import lombok.Data; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.data.redis.core.RedisTemplate; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.io.UnsupportedEncodingException; |
|||
import java.net.URLEncoder; |
|||
import java.util.*; |
|||
import java.util.concurrent.TimeUnit; |
|||
|
|||
|
|||
// 用于实现企业微信相关配置
|
|||
|
|||
@Data |
|||
@Component |
|||
public class QyWxConfig { |
|||
public static String corpid = "ww02f310301953277a"; // 企业的CorpID
|
|||
public static String secret = "GYwyoAGwMwumAVFrFn-RZIc2q11P3pm8NWY9pWDjLqw"; // 应用的凭证密钥
|
|||
public static int AgentId = 1000037; //应用agentid
|
|||
public static String callBackUrl = "https://jy.hxgk.group/QyWxLogin"; |
|||
public static String code = ""; //userCode
|
|||
public static String sendMessage_url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=ACCESS_TOKEN"; |
|||
|
|||
public static RedisPool redisPool; |
|||
|
|||
// 用于回调配置的token
|
|||
public static String sToken = "sM4MFE44fAKdtqvq81HYygqmrdUn"; |
|||
// 用于回调配置的EncodingAESKey
|
|||
public static String sEncodingAESKey = "10cruMoq3ixrQQngJcMN6CzOYrHWmHMpxp2Xn5iYrsk"; |
|||
|
|||
|
|||
// 用于企业微信审批回调配置的token
|
|||
public static String approvalToken = "yCJaB1t"; |
|||
// 用于企业微信审批回调配置的EncodingAESKey
|
|||
public static String approvalEncodingAESKey = "3PEEjYq9sLOm3jdR8huSPRnXOQ8YW7pDnp2Xn5iYrsk"; |
|||
|
|||
|
|||
//企业微信物料出库审批模板ID
|
|||
public static String out_approval_template_id = "3WKiKVCzyLv3Y1LaHZxp4DimQEpCdvYP52HsAUtF"; |
|||
|
|||
// 企业微信库存盘点审批模板Id
|
|||
public static String stockTaking_approval_template_id = "C4RbNbd7KYKHGXimVTc5rkNdVWT92JURzoU4KTgbw"; |
|||
|
|||
// 企业微信入库审批模板Id
|
|||
public static String in_approval_template_id = "3WKiKVEcnH2dsARvP18hwkApF1Ku5dbNd7txbZCS"; |
|||
|
|||
|
|||
// 用于jsapi的url
|
|||
public static String jsApiUrl = "https://jy.hxgk.group/"; |
|||
|
|||
|
|||
@Autowired |
|||
public void setRedisTemplate(RedisPool redisPool) { |
|||
QyWxConfig.redisPool = redisPool; |
|||
} |
|||
|
|||
|
|||
|
|||
// 用于获取企业微信对应token
|
|||
public static String GetQYWXToken(String UserAgent) { |
|||
// 获取redis中当前用户的user-agent
|
|||
String token_redis = redisPool.getRedisTemplateByDb(14).opsForValue().get("wms_access_token_" + UserAgent); |
|||
if (token_redis != null) { |
|||
return token_redis; |
|||
} else { |
|||
String url = String.format(" https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s", QyWxConfig.corpid, QyWxConfig.secret); |
|||
String get = HttpUtils.doGet(url); |
|||
JSONObject jsonObject = JSONObject.parseObject(get); |
|||
Integer errcord = ObjectFormatUtil.toInteger(jsonObject.get("errcode")); |
|||
String accessToken = (String) jsonObject.get("access_token"); |
|||
String errmsg = (String) jsonObject.get("errmsg"); |
|||
if (errcord == 0) { |
|||
// 如果成功获取access_token
|
|||
|
|||
// 定义redis过期时间
|
|||
Long expires_in = 7200L; |
|||
|
|||
// 获取当前redis中存储的key值
|
|||
Set<String> keys = redisPool.getRedisTemplateByDb(14).keys("wms_access_token_*"); |
|||
// 获取遍历器
|
|||
for (String next : keys) { // 如果有下个,则进行遍历
|
|||
// 获取当前key
|
|||
// 当前key对应的token
|
|||
String next_access_token = redisPool.getRedisTemplateByDb(14).opsForValue().get(next); |
|||
if (accessToken.equals(next_access_token)) { |
|||
// 如果当前token相等
|
|||
|
|||
// 获取当前的过期时间
|
|||
expires_in = redisPool.getRedisTemplateByDb(14).opsForValue().getOperations().getExpire(next, TimeUnit.SECONDS); |
|||
} |
|||
} |
|||
|
|||
redisPool.getRedisTemplateByDb(14).opsForValue().set("wms_access_token_" + UserAgent, accessToken); |
|||
redisPool.getRedisTemplateByDb(14).expire("wms_access_token_" + UserAgent, expires_in, TimeUnit.SECONDS); |
|||
|
|||
return accessToken; |
|||
} else { |
|||
// 否则返回空值
|
|||
return "visitToFail:" + errmsg; |
|||
} |
|||
} |
|||
} |
|||
|
|||
// 根据获取到的用户code以及token获取用户id
|
|||
public static JSONObject GetQYWXUserId(String UserAgent) { |
|||
String url = String.format("https://qyapi.weixin.qq.com/cgi-bin/auth/getuserinfo?access_token=%s&code=%s", QyWxConfig.GetQYWXToken(UserAgent), QyWxConfig.code); |
|||
String get = HttpUtils.doGet(url); |
|||
JSONObject jsonObject = JSONObject.parseObject(get); |
|||
return jsonObject; |
|||
|
|||
} |
|||
|
|||
// 用于拼接发送链接
|
|||
public static String getQYWXCodeUrl() { |
|||
String encode = null; |
|||
try { |
|||
encode = URLEncoder.encode(QyWxConfig.callBackUrl, "utf-8"); |
|||
} catch (UnsupportedEncodingException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
String url = String.format("https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base&agentid=%s#wechat_redirect", QyWxConfig.corpid, encode, QyWxConfig.secret); |
|||
return url; |
|||
} |
|||
|
|||
// 获取企业的jsapi_ticket
|
|||
public static JSONObject getQyWxJsApiTicketForEnterprise(String UserAgent) { |
|||
// 如果token不为"",则使用token,否则获取新token
|
|||
String tempToken = GetQYWXToken(UserAgent); |
|||
String url = String.format("https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=%s", tempToken); |
|||
String get = HttpUtils.doGet(url); |
|||
JSONObject jsonObject = JSONObject.parseObject(get); |
|||
return jsonObject; |
|||
} |
|||
|
|||
// 获取应用的jsapi_ticket
|
|||
public static JSONObject getQyWxJsApiTicketForApp(String UserAgent) { |
|||
// 如果token不为"",则使用token,否则获取新token
|
|||
String tempToken = GetQYWXToken(UserAgent); |
|||
String url = String.format("https://qyapi.weixin.qq.com/cgi-bin/ticket/get?access_token=%s&type=agent_config", tempToken); |
|||
String get = HttpUtils.doGet(url); |
|||
JSONObject jsonObject = JSONObject.parseObject(get); |
|||
return jsonObject; |
|||
} |
|||
|
|||
// 获取企业微信中仓储中心负责人标签的成员的userId
|
|||
public static List<String> getQyWxLabelUserListForLabelName(String UserAgent,String labelName) { |
|||
// 获取当前token
|
|||
String tempToken = GetQYWXToken(UserAgent); |
|||
String url = String.format("https://qyapi.weixin.qq.com/cgi-bin/tag/list?access_token=%s", tempToken); |
|||
String get = HttpUtils.doGet(url); |
|||
JSONObject jsonObject = JSONObject.parseObject(get); |
|||
Integer errcode = jsonObject.getInteger("errcode"); |
|||
List<String> userIdList = new ArrayList<>(); |
|||
if (Integer.compare(0, errcode) == 0) { |
|||
JSONArray taglist = jsonObject.getJSONArray("taglist"); |
|||
for (Object o : taglist) { |
|||
qywxLabel qywxLabel = JSONObject.toJavaObject((JSON) o, qywxLabel.class); |
|||
if (qywxLabel.getTagname().contains(labelName)) { |
|||
List<qywxLabelUser> qyWxLabelUserList = getQyWxLabelUserList(tempToken, qywxLabel.getTagid().toString()); |
|||
for (qywxLabelUser qywxLabelUser : qyWxLabelUserList) { |
|||
userIdList.add(qywxLabelUser.getUserid()); |
|||
} |
|||
break; |
|||
} |
|||
} |
|||
} else { |
|||
throw new MyException("获取标签列表失败"); |
|||
} |
|||
return userIdList; |
|||
} |
|||
|
|||
/** |
|||
* 获取当前标签成员 |
|||
* |
|||
* @param tempToken |
|||
* @param TAGID |
|||
* @return |
|||
*/ |
|||
public static List<qywxLabelUser> getQyWxLabelUserList(String tempToken, String TAGID) { |
|||
String url = String.format("https://qyapi.weixin.qq.com/cgi-bin/tag/get?access_token=%s&tagid=%s", tempToken, TAGID); |
|||
String get = HttpUtils.doGet(url); |
|||
JSONObject jsonObject = JSONObject.parseObject(get); |
|||
Integer errcode = jsonObject.getInteger("errcode"); |
|||
List<qywxLabelUser> userList = new ArrayList<>(); |
|||
if (Integer.compare(errcode, 0) == 0) { |
|||
JSONArray userlist = jsonObject.getJSONArray("userlist"); |
|||
for (Object o : userlist) { |
|||
qywxLabelUser qywxLabelUser = JSONObject.toJavaObject((JSON) o, qywxLabelUser.class); |
|||
userList.add(qywxLabelUser); |
|||
} |
|||
} else { |
|||
throw new MyException("获取标签成员失败"); |
|||
} |
|||
return userList; |
|||
} |
|||
|
|||
/** |
|||
* 用于获取当前企业微信部门详情 |
|||
* |
|||
* @param UserAgent |
|||
* @param id |
|||
* @return |
|||
*/ |
|||
public static qywxDepartment getQyWxDepartment(String UserAgent, Integer id) { |
|||
String tempToken = GetQYWXToken(UserAgent); |
|||
String url = String.format("https://qyapi.weixin.qq.com/cgi-bin/department/get?access_token=%s&id=%s", tempToken, id); |
|||
String get = HttpUtils.doGet(url); |
|||
JSONObject jsonObject = JSONObject.parseObject(get); |
|||
Integer errcode = jsonObject.getInteger("errcode"); |
|||
if (Integer.compare(errcode, 0) == 0) { |
|||
qywxDepartment qywxDepartment = JSONObject.toJavaObject(jsonObject.getJSONObject("department"), qywxDepartment.class); |
|||
return qywxDepartment; |
|||
} else { |
|||
throw new MyException("获取部门信息失败"); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 用于获取企业微信部门列表 |
|||
* |
|||
* @param UserAgent |
|||
* @return |
|||
*/ |
|||
public static List<qywxDepartment> getQyWxDepartmentList(String UserAgent, Integer id) { |
|||
String tempToken = GetQYWXToken(UserAgent); |
|||
String url = String.format("https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=%s&id=%s", tempToken, id); |
|||
String get = HttpUtils.doGet(url); |
|||
JSONObject jsonObject = JSONObject.parseObject(get); |
|||
Integer errcode = jsonObject.getInteger("errcode"); |
|||
if (Integer.compare(errcode, 0) == 0) { |
|||
List<qywxDepartment> qywxDepartmentList = new ArrayList<>(); |
|||
JSONArray department = jsonObject.getJSONArray("department"); |
|||
for (int i = 0; i < department.size(); i++) { |
|||
qywxDepartment qywxDepartment = JSONObject.toJavaObject(department.getJSONObject(i), qywxDepartment.class); |
|||
qywxDepartmentList.add(qywxDepartment); |
|||
} |
|||
return qywxDepartmentList; |
|||
} else { |
|||
throw new MyException("获取部门列表失败"); |
|||
} |
|||
} |
|||
|
|||
|
|||
public static List<String> getQyWxDepartmentUserList(String UserAgent, Integer id) { |
|||
String tempToken = GetQYWXToken(UserAgent); |
|||
String url = String.format("https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token=%s&department_id=%s&fetch_child=1", tempToken, id); |
|||
String get = HttpUtils.doGet(url); |
|||
JSONObject jsonObject = JSONObject.parseObject(get); |
|||
Integer errcode = jsonObject.getInteger("errcode"); |
|||
List<String> result = new ArrayList<>(); |
|||
if (Integer.compare(errcode, 0) == 0) { |
|||
JSONArray userlist = jsonObject.getJSONArray("userlist"); |
|||
for (int i = 0; i < userlist.size(); i++) { |
|||
JSONObject data = userlist.getJSONObject(i); |
|||
String userid = data.getString("userid"); |
|||
result.add(userid); |
|||
} |
|||
return result; |
|||
} else { |
|||
throw new MyException("获取部门列表失败"); |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
public static List<Integer> getQyWxDepartmentIdList(String UserAgent,Integer id){ |
|||
String tempToken = GetQYWXToken(UserAgent); |
|||
String url = String.format("https://qyapi.weixin.qq.com/cgi-bin/department/simplelist?access_token=%s&id=%s", tempToken, id); |
|||
String get = HttpUtils.doGet(url); |
|||
JSONObject jsonObject = JSONObject.parseObject(get); |
|||
Integer errcode = jsonObject.getInteger("errcode"); |
|||
List<Integer> resultList = new ArrayList<>(); |
|||
if (Integer.compare(errcode, 0) == 0) { |
|||
JSONArray department = jsonObject.getJSONArray("department_id"); |
|||
for (int i = 0; i < department.size(); i++) { |
|||
JSONObject value = department.getJSONObject(i); |
|||
Integer vid = value.getInteger("id"); |
|||
resultList.add(vid); |
|||
} |
|||
} |
|||
return resultList; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,61 @@ |
|||
package com.dreamchaser.depository_manage.config.QyWxJMJM.com.qq.weixin.mp.aes; |
|||
|
|||
|
|||
|
|||
@SuppressWarnings("serial") |
|||
public class AesException extends Exception { |
|||
|
|||
public final static int OK = 0; |
|||
public final static int ValidateSignatureError = -40001; |
|||
public final static int ParseXmlError = -40002; |
|||
public final static int ComputeSignatureError = -40003; |
|||
public final static int IllegalAesKey = -40004; |
|||
public final static int ValidateCorpidError = -40005; |
|||
public final static int EncryptAESError = -40006; |
|||
public final static int DecryptAESError = -40007; |
|||
public final static int IllegalBuffer = -40008; |
|||
//public final static int EncodeBase64Error = -40009;
|
|||
//public final static int DecodeBase64Error = -40010;
|
|||
//public final static int GenReturnXmlError = -40011;
|
|||
|
|||
private int code; |
|||
|
|||
private static String getMessage(int code) { |
|||
switch (code) { |
|||
case ValidateSignatureError: |
|||
return "签名验证错误"; |
|||
case ParseXmlError: |
|||
return "xml解析失败"; |
|||
case ComputeSignatureError: |
|||
return "sha加密生成签名失败"; |
|||
case IllegalAesKey: |
|||
return "SymmetricKey非法"; |
|||
case ValidateCorpidError: |
|||
return "corpid校验失败"; |
|||
case EncryptAESError: |
|||
return "aes加密失败"; |
|||
case DecryptAESError: |
|||
return "aes解密失败"; |
|||
case IllegalBuffer: |
|||
return "解密后得到的buffer非法"; |
|||
// case EncodeBase64Error:
|
|||
// return "base64加密错误";
|
|||
// case DecodeBase64Error:
|
|||
// return "base64解密错误";
|
|||
// case GenReturnXmlError:
|
|||
// return "xml生成失败";
|
|||
default: |
|||
return null; // cannot be
|
|||
} |
|||
} |
|||
|
|||
public int getCode() { |
|||
return code; |
|||
} |
|||
|
|||
AesException(int code) { |
|||
super(getMessage(code)); |
|||
this.code = code; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
package com.dreamchaser.depository_manage.config.QyWxJMJM.com.qq.weixin.mp.aes; |
|||
|
|||
import java.util.ArrayList; |
|||
|
|||
class ByteGroup { |
|||
ArrayList<Byte> byteContainer = new ArrayList<Byte>(); |
|||
|
|||
public byte[] toBytes() { |
|||
byte[] bytes = new byte[byteContainer.size()]; |
|||
for (int i = 0; i < byteContainer.size(); i++) { |
|||
bytes[i] = byteContainer.get(i); |
|||
} |
|||
return bytes; |
|||
} |
|||
|
|||
public ByteGroup addBytes(byte[] bytes) { |
|||
for (byte b : bytes) { |
|||
byteContainer.add(b); |
|||
} |
|||
return this; |
|||
} |
|||
|
|||
public int size() { |
|||
return byteContainer.size(); |
|||
} |
|||
} |
|||
@ -0,0 +1,67 @@ |
|||
/** |
|||
* 对企业微信发送给企业后台的消息加解密示例代码. |
|||
* |
|||
* @copyright Copyright (c) 1998-2014 Tencent Inc. |
|||
*/ |
|||
|
|||
// ------------------------------------------------------------------------
|
|||
|
|||
package com.dreamchaser.depository_manage.config.QyWxJMJM.com.qq.weixin.mp.aes; |
|||
|
|||
import java.nio.charset.Charset; |
|||
import java.util.Arrays; |
|||
|
|||
/** |
|||
* 提供基于PKCS7算法的加解密接口. |
|||
*/ |
|||
class PKCS7Encoder { |
|||
static Charset CHARSET = Charset.forName("utf-8"); |
|||
static int BLOCK_SIZE = 32; |
|||
|
|||
/** |
|||
* 获得对明文进行补位填充的字节. |
|||
* |
|||
* @param count 需要进行填充补位操作的明文字节个数 |
|||
* @return 补齐用的字节数组 |
|||
*/ |
|||
static byte[] encode(int count) { |
|||
// 计算需要填充的位数
|
|||
int amountToPad = BLOCK_SIZE - (count % BLOCK_SIZE); |
|||
if (amountToPad == 0) { |
|||
amountToPad = BLOCK_SIZE; |
|||
} |
|||
// 获得补位所用的字符
|
|||
char padChr = chr(amountToPad); |
|||
String tmp = new String(); |
|||
for (int index = 0; index < amountToPad; index++) { |
|||
tmp += padChr; |
|||
} |
|||
return tmp.getBytes(CHARSET); |
|||
} |
|||
|
|||
/** |
|||
* 删除解密后明文的补位字符 |
|||
* |
|||
* @param decrypted 解密后的明文 |
|||
* @return 删除补位字符后的明文 |
|||
*/ |
|||
static byte[] decode(byte[] decrypted) { |
|||
int pad = (int) decrypted[decrypted.length - 1]; |
|||
if (pad < 1 || pad > 32) { |
|||
pad = 0; |
|||
} |
|||
return Arrays.copyOfRange(decrypted, 0, decrypted.length - pad); |
|||
} |
|||
|
|||
/** |
|||
* 将数字转化成ASCII码对应的字符,用于对明文进行补码 |
|||
* |
|||
* @param a 需要转化的数字 |
|||
* @return 转化得到的字符 |
|||
*/ |
|||
static char chr(int a) { |
|||
byte target = (byte) (a & 0xFF); |
|||
return (char) target; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,61 @@ |
|||
/** |
|||
* 对企业微信发送给企业后台的消息加解密示例代码. |
|||
* |
|||
* @copyright Copyright (c) 1998-2014 Tencent Inc. |
|||
*/ |
|||
|
|||
// ------------------------------------------------------------------------
|
|||
|
|||
package com.dreamchaser.depository_manage.config.QyWxJMJM.com.qq.weixin.mp.aes; |
|||
|
|||
import java.security.MessageDigest; |
|||
import java.util.Arrays; |
|||
|
|||
/** |
|||
* SHA1 class |
|||
* |
|||
* 计算消息签名接口. |
|||
*/ |
|||
class SHA1 { |
|||
|
|||
/** |
|||
* 用SHA1算法生成安全签名 |
|||
* @param token 票据 |
|||
* @param timestamp 时间戳 |
|||
* @param nonce 随机字符串 |
|||
* @param encrypt 密文 |
|||
* @return 安全签名 |
|||
* @throws AesException |
|||
*/ |
|||
public static String getSHA1(String token, String timestamp, String nonce, String encrypt) throws AesException |
|||
{ |
|||
try { |
|||
String[] array = new String[] { token, timestamp, nonce, encrypt }; |
|||
StringBuffer sb = new StringBuffer(); |
|||
// 字符串排序
|
|||
Arrays.sort(array); |
|||
for (int i = 0; i < 4; i++) { |
|||
sb.append(array[i]); |
|||
} |
|||
String str = sb.toString(); |
|||
// SHA1签名生成
|
|||
MessageDigest md = MessageDigest.getInstance("SHA-1"); |
|||
md.update(str.getBytes()); |
|||
byte[] digest = md.digest(); |
|||
|
|||
StringBuffer hexstr = new StringBuffer(); |
|||
String shaHex = ""; |
|||
for (int i = 0; i < digest.length; i++) { |
|||
shaHex = Integer.toHexString(digest[i] & 0xFF); |
|||
if (shaHex.length() < 2) { |
|||
hexstr.append(0); |
|||
} |
|||
hexstr.append(shaHex); |
|||
} |
|||
return hexstr.toString(); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
throw new AesException(AesException.ComputeSignatureError); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,289 @@ |
|||
/** |
|||
* 对企业微信发送给企业后台的消息加解密示例代码. |
|||
* |
|||
* @copyright Copyright (c) 1998-2014 Tencent Inc. |
|||
*/ |
|||
|
|||
// ------------------------------------------------------------------------
|
|||
|
|||
/** |
|||
* 针对org.apache.commons.codec.binary.Base64, |
|||
* 需要导入架包commons-codec-1.9(或commons-codec-1.8等其他版本) |
|||
* 官方下载地址:http://commons.apache.org/proper/commons-codec/download_codec.cgi
|
|||
*/ |
|||
package com.dreamchaser.depository_manage.config.QyWxJMJM.com.qq.weixin.mp.aes; |
|||
|
|||
import java.nio.charset.Charset; |
|||
import java.util.Arrays; |
|||
import java.util.Random; |
|||
|
|||
import javax.crypto.Cipher; |
|||
import javax.crypto.spec.IvParameterSpec; |
|||
import javax.crypto.spec.SecretKeySpec; |
|||
|
|||
import org.apache.commons.codec.binary.Base64; |
|||
|
|||
/** |
|||
* 提供接收和推送给企业微信消息的加解密接口(UTF8编码的字符串). |
|||
* <ol> |
|||
* <li>第三方回复加密消息给企业微信</li> |
|||
* <li>第三方收到企业微信发送的消息,验证消息的安全性,并对消息进行解密。</li> |
|||
* </ol> |
|||
* 说明:异常java.security.InvalidKeyException:illegal Key Size的解决方案 |
|||
* <ol> |
|||
* <li>在官方网站下载JCE无限制权限策略文件(JDK7的下载地址: |
|||
* http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html</li>
|
|||
* <li>下载后解压,可以看到local_policy.jar和US_export_policy.jar以及readme.txt</li> |
|||
* <li>如果安装了JRE,将两个jar文件放到%JRE_HOME%\lib\security目录下覆盖原来的文件</li> |
|||
* <li>如果安装了JDK,将两个jar文件放到%JDK_HOME%\jre\lib\security目录下覆盖原来文件</li> |
|||
* </ol> |
|||
*/ |
|||
public class WXBizMsgCrypt { |
|||
static Charset CHARSET = Charset.forName("utf-8"); |
|||
Base64 base64 = new Base64(); |
|||
byte[] aesKey; |
|||
String token; |
|||
String receiveid; |
|||
|
|||
/** |
|||
* 构造函数 |
|||
* @param token 企业微信后台,开发者设置的token |
|||
* @param encodingAesKey 企业微信后台,开发者设置的EncodingAESKey |
|||
* @param receiveid, 不同场景含义不同,详见文档 |
|||
* |
|||
* @throws AesException 执行失败,请查看该异常的错误码和具体的错误信息 |
|||
*/ |
|||
public WXBizMsgCrypt(String token, String encodingAesKey, String receiveid) throws AesException { |
|||
if (encodingAesKey.length() != 43) { |
|||
throw new AesException(AesException.IllegalAesKey); |
|||
} |
|||
|
|||
this.token = token; |
|||
this.receiveid = receiveid; |
|||
aesKey = Base64.decodeBase64(encodingAesKey + "="); |
|||
} |
|||
|
|||
// 生成4个字节的网络字节序
|
|||
byte[] getNetworkBytesOrder(int sourceNumber) { |
|||
byte[] orderBytes = new byte[4]; |
|||
orderBytes[3] = (byte) (sourceNumber & 0xFF); |
|||
orderBytes[2] = (byte) (sourceNumber >> 8 & 0xFF); |
|||
orderBytes[1] = (byte) (sourceNumber >> 16 & 0xFF); |
|||
orderBytes[0] = (byte) (sourceNumber >> 24 & 0xFF); |
|||
return orderBytes; |
|||
} |
|||
|
|||
// 还原4个字节的网络字节序
|
|||
int recoverNetworkBytesOrder(byte[] orderBytes) { |
|||
int sourceNumber = 0; |
|||
for (int i = 0; i < 4; i++) { |
|||
sourceNumber <<= 8; |
|||
sourceNumber |= orderBytes[i] & 0xff; |
|||
} |
|||
return sourceNumber; |
|||
} |
|||
|
|||
// 随机生成16位字符串
|
|||
String getRandomStr() { |
|||
String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; |
|||
Random random = new Random(); |
|||
StringBuffer sb = new StringBuffer(); |
|||
for (int i = 0; i < 16; i++) { |
|||
int number = random.nextInt(base.length()); |
|||
sb.append(base.charAt(number)); |
|||
} |
|||
return sb.toString(); |
|||
} |
|||
|
|||
/** |
|||
* 对明文进行加密. |
|||
* |
|||
* @param text 需要加密的明文 |
|||
* @return 加密后base64编码的字符串 |
|||
* @throws AesException aes加密失败 |
|||
*/ |
|||
String encrypt(String randomStr, String text) throws AesException { |
|||
ByteGroup byteCollector = new ByteGroup(); |
|||
byte[] randomStrBytes = randomStr.getBytes(CHARSET); |
|||
byte[] textBytes = text.getBytes(CHARSET); |
|||
byte[] networkBytesOrder = getNetworkBytesOrder(textBytes.length); |
|||
byte[] receiveidBytes = receiveid.getBytes(CHARSET); |
|||
|
|||
// randomStr + networkBytesOrder + text + receiveid
|
|||
byteCollector.addBytes(randomStrBytes); |
|||
byteCollector.addBytes(networkBytesOrder); |
|||
byteCollector.addBytes(textBytes); |
|||
byteCollector.addBytes(receiveidBytes); |
|||
|
|||
// ... + pad: 使用自定义的填充方式对明文进行补位填充
|
|||
byte[] padBytes = PKCS7Encoder.encode(byteCollector.size()); |
|||
byteCollector.addBytes(padBytes); |
|||
|
|||
// 获得最终的字节流, 未加密
|
|||
byte[] unencrypted = byteCollector.toBytes(); |
|||
|
|||
try { |
|||
// 设置加密模式为AES的CBC模式
|
|||
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); |
|||
SecretKeySpec keySpec = new SecretKeySpec(aesKey, "AES"); |
|||
IvParameterSpec iv = new IvParameterSpec(aesKey, 0, 16); |
|||
cipher.init(Cipher.ENCRYPT_MODE, keySpec, iv); |
|||
|
|||
// 加密
|
|||
byte[] encrypted = cipher.doFinal(unencrypted); |
|||
|
|||
// 使用BASE64对加密后的字符串进行编码
|
|||
String base64Encrypted = base64.encodeToString(encrypted); |
|||
|
|||
return base64Encrypted; |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
throw new AesException(AesException.EncryptAESError); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 对密文进行解密. |
|||
* |
|||
* @param text 需要解密的密文 |
|||
* @return 解密得到的明文 |
|||
* @throws AesException aes解密失败 |
|||
*/ |
|||
String decrypt(String text) throws AesException { |
|||
byte[] original; |
|||
try { |
|||
// 设置解密模式为AES的CBC模式
|
|||
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); |
|||
SecretKeySpec key_spec = new SecretKeySpec(aesKey, "AES"); |
|||
IvParameterSpec iv = new IvParameterSpec(Arrays.copyOfRange(aesKey, 0, 16)); |
|||
cipher.init(Cipher.DECRYPT_MODE, key_spec, iv); |
|||
|
|||
// 使用BASE64对密文进行解码
|
|||
byte[] encrypted = Base64.decodeBase64(text); |
|||
|
|||
// 解密
|
|||
original = cipher.doFinal(encrypted); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
throw new AesException(AesException.DecryptAESError); |
|||
} |
|||
|
|||
String xmlContent, from_receiveid; |
|||
try { |
|||
// 去除补位字符
|
|||
byte[] bytes = PKCS7Encoder.decode(original); |
|||
|
|||
// 分离16位随机字符串,网络字节序和receiveid
|
|||
byte[] networkOrder = Arrays.copyOfRange(bytes, 16, 20); |
|||
|
|||
int xmlLength = recoverNetworkBytesOrder(networkOrder); |
|||
|
|||
xmlContent = new String(Arrays.copyOfRange(bytes, 20, 20 + xmlLength), CHARSET); |
|||
from_receiveid = new String(Arrays.copyOfRange(bytes, 20 + xmlLength, bytes.length), |
|||
CHARSET); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
throw new AesException(AesException.IllegalBuffer); |
|||
} |
|||
|
|||
// receiveid不相同的情况
|
|||
if (!from_receiveid.equals(receiveid)) { |
|||
throw new AesException(AesException.ValidateCorpidError); |
|||
} |
|||
return xmlContent; |
|||
|
|||
} |
|||
|
|||
/** |
|||
* 将企业微信回复用户的消息加密打包. |
|||
* <ol> |
|||
* <li>对要发送的消息进行AES-CBC加密</li> |
|||
* <li>生成安全签名</li> |
|||
* <li>将消息密文和安全签名打包成xml格式</li> |
|||
* </ol> |
|||
* |
|||
* @param replyMsg 企业微信待回复用户的消息,xml格式的字符串 |
|||
* @param timeStamp 时间戳,可以自己生成,也可以用URL参数的timestamp |
|||
* @param nonce 随机串,可以自己生成,也可以用URL参数的nonce |
|||
* |
|||
* @return 加密后的可以直接回复用户的密文,包括msg_signature, timestamp, nonce, encrypt的xml格式的字符串 |
|||
* @throws AesException 执行失败,请查看该异常的错误码和具体的错误信息 |
|||
*/ |
|||
public String EncryptMsg(String replyMsg, String timeStamp, String nonce) throws AesException { |
|||
// 加密
|
|||
String encrypt = encrypt(getRandomStr(), replyMsg); |
|||
|
|||
// 生成安全签名
|
|||
if (timeStamp == "") { |
|||
timeStamp = Long.toString(System.currentTimeMillis()); |
|||
} |
|||
|
|||
String signature = SHA1.getSHA1(token, timeStamp, nonce, encrypt); |
|||
|
|||
// System.out.println("发送给平台的签名是: " + signature[1].toString());
|
|||
// 生成发送的xml
|
|||
String result = XMLParse.generate(encrypt, signature, timeStamp, nonce); |
|||
return result; |
|||
} |
|||
|
|||
/** |
|||
* 检验消息的真实性,并且获取解密后的明文. |
|||
* <ol> |
|||
* <li>利用收到的密文生成安全签名,进行签名验证</li> |
|||
* <li>若验证通过,则提取xml中的加密消息</li> |
|||
* <li>对消息进行解密</li> |
|||
* </ol> |
|||
* |
|||
* @param msgSignature 签名串,对应URL参数的msg_signature |
|||
* @param timeStamp 时间戳,对应URL参数的timestamp |
|||
* @param nonce 随机串,对应URL参数的nonce |
|||
* @param postData 密文,对应POST请求的数据 |
|||
* |
|||
* @return 解密后的原文 |
|||
* @throws AesException 执行失败,请查看该异常的错误码和具体的错误信息 |
|||
*/ |
|||
public String DecryptMsg(String msgSignature, String timeStamp, String nonce, String postData) |
|||
throws AesException { |
|||
|
|||
// 密钥,公众账号的app secret
|
|||
// 提取密文
|
|||
Object[] encrypt = XMLParse.extract(postData); |
|||
|
|||
// 验证安全签名
|
|||
String signature = SHA1.getSHA1(token, timeStamp, nonce, encrypt[1].toString()); |
|||
|
|||
// 和URL中的签名比较是否相等
|
|||
// System.out.println("第三方收到URL中的签名:" + msg_sign);
|
|||
// System.out.println("第三方校验签名:" + signature);
|
|||
if (!signature.equals(msgSignature)) { |
|||
throw new AesException(AesException.ValidateSignatureError); |
|||
} |
|||
|
|||
// 解密
|
|||
String result = decrypt(encrypt[1].toString()); |
|||
return result; |
|||
} |
|||
|
|||
/** |
|||
* 验证URL |
|||
* @param msgSignature 签名串,对应URL参数的msg_signature |
|||
* @param timeStamp 时间戳,对应URL参数的timestamp |
|||
* @param nonce 随机串,对应URL参数的nonce |
|||
* @param echoStr 随机串,对应URL参数的echostr |
|||
* |
|||
* @return 解密之后的echostr |
|||
* @throws AesException 执行失败,请查看该异常的错误码和具体的错误信息 |
|||
*/ |
|||
public String VerifyURL(String msgSignature, String timeStamp, String nonce, String echoStr) |
|||
throws AesException { |
|||
String signature = SHA1.getSHA1(token, timeStamp, nonce, echoStr); |
|||
|
|||
if (!signature.equals(msgSignature)) { |
|||
throw new AesException(AesException.ValidateSignatureError); |
|||
} |
|||
|
|||
String result = decrypt(echoStr); |
|||
return result; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,104 @@ |
|||
/** |
|||
* 对企业微信发送给企业后台的消息加解密示例代码. |
|||
* |
|||
* @copyright Copyright (c) 1998-2014 Tencent Inc. |
|||
*/ |
|||
|
|||
// ------------------------------------------------------------------------
|
|||
|
|||
package com.dreamchaser.depository_manage.config.QyWxJMJM.com.qq.weixin.mp.aes; |
|||
|
|||
import java.io.StringReader; |
|||
|
|||
import javax.xml.parsers.DocumentBuilder; |
|||
import javax.xml.parsers.DocumentBuilderFactory; |
|||
|
|||
import org.w3c.dom.Document; |
|||
import org.w3c.dom.Element; |
|||
import org.w3c.dom.NodeList; |
|||
import org.xml.sax.InputSource; |
|||
|
|||
/** |
|||
* XMLParse class |
|||
* |
|||
* 提供提取消息格式中的密文及生成回复消息格式的接口. |
|||
*/ |
|||
class XMLParse { |
|||
|
|||
/** |
|||
* 提取出xml数据包中的加密消息 |
|||
* @param xmltext 待提取的xml字符串 |
|||
* @return 提取出的加密消息字符串 |
|||
* @throws AesException |
|||
*/ |
|||
public static Object[] extract(String xmltext) throws AesException { |
|||
Object[] result = new Object[3]; |
|||
try { |
|||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); |
|||
|
|||
String FEATURE = null; |
|||
// This is the PRIMARY defense. If DTDs (doctypes) are disallowed, almost all XML entity attacks are prevented
|
|||
// Xerces 2 only - http://xerces.apache.org/xerces2-j/features.html#disallow-doctype-decl
|
|||
FEATURE = "http://apache.org/xml/features/disallow-doctype-decl"; |
|||
dbf.setFeature(FEATURE, true); |
|||
|
|||
// If you can't completely disable DTDs, then at least do the following:
|
|||
// Xerces 1 - http://xerces.apache.org/xerces-j/features.html#external-general-entities
|
|||
// Xerces 2 - http://xerces.apache.org/xerces2-j/features.html#external-general-entities
|
|||
// JDK7+ - http://xml.org/sax/features/external-general-entities
|
|||
FEATURE = "http://xml.org/sax/features/external-general-entities"; |
|||
dbf.setFeature(FEATURE, false); |
|||
|
|||
// Xerces 1 - http://xerces.apache.org/xerces-j/features.html#external-parameter-entities
|
|||
// Xerces 2 - http://xerces.apache.org/xerces2-j/features.html#external-parameter-entities
|
|||
// JDK7+ - http://xml.org/sax/features/external-parameter-entities
|
|||
FEATURE = "http://xml.org/sax/features/external-parameter-entities"; |
|||
dbf.setFeature(FEATURE, false); |
|||
|
|||
// Disable external DTDs as well
|
|||
FEATURE = "http://apache.org/xml/features/nonvalidating/load-external-dtd"; |
|||
dbf.setFeature(FEATURE, false); |
|||
|
|||
// and these as well, per Timothy Morgan's 2014 paper: "XML Schema, DTD, and Entity Attacks"
|
|||
dbf.setXIncludeAware(false); |
|||
dbf.setExpandEntityReferences(false); |
|||
|
|||
// And, per Timothy Morgan: "If for some reason support for inline DOCTYPEs are a requirement, then
|
|||
// ensure the entity settings are disabled (as shown above) and beware that SSRF attacks
|
|||
// (http://cwe.mitre.org/data/definitions/918.html) and denial
|
|||
// of service attacks (such as billion laughs or decompression bombs via "jar:") are a risk."
|
|||
|
|||
// remaining parser logic
|
|||
DocumentBuilder db = dbf.newDocumentBuilder(); |
|||
StringReader sr = new StringReader(xmltext); |
|||
InputSource is = new InputSource(sr); |
|||
Document document = db.parse(is); |
|||
|
|||
Element root = document.getDocumentElement(); |
|||
NodeList nodelist1 = root.getElementsByTagName("Encrypt"); |
|||
result[0] = 0; |
|||
result[1] = nodelist1.item(0).getTextContent(); |
|||
return result; |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
throw new AesException(AesException.ParseXmlError); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 生成xml消息 |
|||
* @param encrypt 加密后的消息密文 |
|||
* @param signature 安全签名 |
|||
* @param timestamp 时间戳 |
|||
* @param nonce 随机字符串 |
|||
* @return 生成的xml字符串 |
|||
*/ |
|||
public static String generate(String encrypt, String signature, String timestamp, String nonce) { |
|||
|
|||
String format = "<xml>\n" + "<Encrypt><![CDATA[%1$s]]></Encrypt>\n" |
|||
+ "<MsgSignature><![CDATA[%2$s]]></MsgSignature>\n" |
|||
+ "<TimeStamp>%3$s</TimeStamp>\n" + "<Nonce><![CDATA[%4$s]]></Nonce>\n" + "</xml>"; |
|||
return String.format(format, encrypt, signature, timestamp, nonce); |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,59 @@ |
|||
package com.dreamchaser.depository_manage.config.QyWx_approval_template; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.util.List; |
|||
|
|||
|
|||
/** |
|||
* 用于审批模板的创建 |
|||
*/ |
|||
@Data |
|||
public class ApprovalTemplate { |
|||
|
|||
/** |
|||
* 申请人userid,此审批申请将以此员工身份提交,申请人需在应用可见范围内 |
|||
*/ |
|||
private String creator_userid; |
|||
|
|||
/** |
|||
* 模板id。可在“获取审批申请详情”、“审批状态变化回调通知”中获得,也可在审批模板的模板编辑页面链接中获得。暂不支持通过接口提交[打卡补卡][调班]模板审批单。 |
|||
*/ |
|||
private String template_id; |
|||
|
|||
/** |
|||
* 审批人模式:0-通过接口指定审批人、抄送人(此时approver、notifyer等参数可用); 1-使用此模板在管理后台设置的审批流程(需要保证审批流程中没有“申请人自选”节点),支持条件审批。默认为0 |
|||
*/ |
|||
private int use_template_approver; |
|||
|
|||
/** |
|||
* 提单者提单部门id,不填默认为主部门 |
|||
*/ |
|||
private int choose_department; |
|||
|
|||
|
|||
/** |
|||
* 抄送人节点userid列表,仅use_template_approver为0时生效。 |
|||
*/ |
|||
private List<String> notifyer; |
|||
|
|||
/** |
|||
* 抄送方式:1-提单时抄送(默认值); 2-单据通过后抄送;3-提单和单据通过后抄送。仅use_template_approver为0时生效。 |
|||
*/ |
|||
private int notify_type; |
|||
|
|||
/** |
|||
* 审批申请数据,可定义审批申请中各个控件的值,其中必填项必须有值,选填项可为空,数据结构同“获取审批申请详情”接口返回值中同名参数“apply_data” |
|||
*/ |
|||
private Approval_template_apply_data apply_data; |
|||
|
|||
/** |
|||
* 摘要信息,用于显示在审批通知卡片、审批列表的摘要信息,最多3行 |
|||
*/ |
|||
private List<Object> summary_list; |
|||
|
|||
|
|||
private List<Approval_template_approver> approver; |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
package com.dreamchaser.depository_manage.config.QyWx_approval_template; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 审批申请数据,可定义审批申请中各个控件的值,其中必填项必须有值,选填项可为空,数据结构同“获取审批申请详情”接口返回值中同名参数“apply_data” |
|||
*/ |
|||
@Data |
|||
public class Approval_template_apply_data { |
|||
/** |
|||
* 控件类型:Text-文本;Textarea-多行文本;Number-数字;Money-金额;Date-日期/日期+时间;Selector-单选/多选; |
|||
* Contact-成员/部门;Tips-说明文字;File-附件;Table-明细;Location-位置;RelatedApproval-关联审批单;Formula-公式;DateRange-时长 |
|||
*/ |
|||
private List<Approval_template_apply_data_contents> contents; |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
package com.dreamchaser.depository_manage.config.QyWx_approval_template; |
|||
|
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* 控件相关数据 |
|||
*/ |
|||
@Data |
|||
public class Approval_template_apply_data_contents { |
|||
/** |
|||
* 控件类型:Text-文本;Textarea-多行文本;Number-数字;Money-金额;Date-日期/日期+时间;Selector-单选/多选; |
|||
* ;Contact-成员/部门;Tips-说明文字;File-附件;Table-明细;Location-位置;RelatedApproval-关联审批单;Formula-公式;DateRange-时长; |
|||
*/ |
|||
private String control; |
|||
/** |
|||
* 控件id:控件的唯一id,可通过“获取审批模板详情”接口获取 |
|||
*/ |
|||
private String id; |
|||
|
|||
/** |
|||
* 控件值 ,需在此为申请人在各个控件中填写内容不同控件有不同的赋值参数,具体说明详见附录。模板配置的控件属性为必填时,对应value值需要有值。 |
|||
*/ |
|||
private Object value; |
|||
|
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
package com.dreamchaser.depository_manage.config.QyWx_approval_template; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 审批流程信息,用于指定审批申请的审批流程,支持单人审批、多人会签、多人或签,可能有多个审批节点,仅use_template_approver为0时生效。 |
|||
*/ |
|||
@Data |
|||
public class Approval_template_approver { |
|||
/** |
|||
* 节点审批方式:1-或签;2-会签,仅在节点为多人审批时有效 |
|||
*/ |
|||
private int attr; |
|||
|
|||
/** |
|||
* 审批节点审批人userid列表,若为多人会签、多人或签,需填写每个人的userid |
|||
*/ |
|||
private List<String> userid; |
|||
|
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
package com.dreamchaser.depository_manage.config.QyWx_approval_template; |
|||
|
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* 摘要行信息 |
|||
*/ |
|||
@Data |
|||
public class Approval_template_summary_info { |
|||
/** |
|||
* 摘要行显示文字,用于记录列表和消息通知的显示,不要超过20个字符 |
|||
*/ |
|||
private String text; |
|||
/** |
|||
* 摘要行显示语言,中文:zh_CN(注意不是zh-CN),英文:en |
|||
*/ |
|||
private String lang; |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
package com.dreamchaser.depository_manage.config.QyWx_template_card; |
|||
|
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* 消息基类(企业号 -> 普通用户) |
|||
* |
|||
*/ |
|||
@Data |
|||
public class BaseMessage { |
|||
// 否 成员ID列表(消息接收者,多个接收者用'|'分隔,最多支持1000个)。特殊情况:指定为@all,则向该企业应用的全部成员发送
|
|||
private String touser; |
|||
// 否 部门ID列表,多个接收者用'|'分隔,最多支持100个。当touser为@all时忽略本参数
|
|||
private String toparty; |
|||
// 否 标签ID列表,多个接收者用'|'分隔,最多支持100个。当touser为@all时忽略本参数
|
|||
private String totag; |
|||
// 是 消息类型
|
|||
private String msgtype; |
|||
// 是 企业应用的id,整型。可在应用的设置页面查看
|
|||
private int agentid; |
|||
// 否 表示是否开启id转译,0表示否,1表示是,默认0
|
|||
private int enable_id_trans; |
|||
// 否 表示是否开启重复消息检查,0表示否,1表示是,默认0
|
|||
private int enable_duplicate_check; |
|||
// 否 表示是否重复消息检查的时间间隔,默认1800s,最大不超过4小时
|
|||
private int duplicate_check_interval; |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
package com.dreamchaser.depository_manage.config.QyWx_template_card; |
|||
|
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* 按钮交互性 |
|||
* |
|||
*/ |
|||
@Data |
|||
public class ButtonInteraction extends BaseMessage { |
|||
// 模板卡片
|
|||
private TemplateCard_button_interaction template_card; |
|||
// 否 表示是否是保密消息,0表示否,1表示是,默认0
|
|||
private int safe; |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
package com.dreamchaser.depository_manage.config.QyWx_template_card; |
|||
|
|||
import lombok.Data; |
|||
|
|||
|
|||
/** |
|||
* 用于发送markdown消息 |
|||
*/ |
|||
@Data |
|||
public class MessageByMarkDown extends BaseMessage { |
|||
private Object markdown; |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
package com.dreamchaser.depository_manage.config.QyWx_template_card; |
|||
|
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* 操作 |
|||
*/ |
|||
@Data |
|||
public class TemplateCard_action { |
|||
/** |
|||
* 操作的描述文案 |
|||
*/ |
|||
private String text; |
|||
/** |
|||
* 操作key值,用户点击后,会产生回调事件将本参数作为EventKey返回,回调事件会带上该key值,最长支持1024字节,不可重复 |
|||
*/ |
|||
private String key; |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
package com.dreamchaser.depository_manage.config.QyWx_template_card; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.xml.bind.annotation.XmlRootElement; |
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 卡片右上角更多操作按钮 |
|||
*/ |
|||
@XmlRootElement |
|||
@Data |
|||
public class TemplateCard_action_menu { |
|||
/** |
|||
* 更多操作界面的描述 |
|||
*/ |
|||
private String desc; |
|||
|
|||
/** |
|||
* 操作列表,列表长度取值范围为 [1, 3] |
|||
*/ |
|||
private List<TemplateCard_action> action_list; |
|||
|
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
package com.dreamchaser.depository_manage.config.QyWx_template_card; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.xml.bind.annotation.XmlRootElement; |
|||
|
|||
/** |
|||
* 按钮 |
|||
*/ |
|||
@XmlRootElement |
|||
@Data |
|||
public class TemplateCard_button { |
|||
/** |
|||
* 按钮点击事件类型,0 或不填代表回调点击事件,1 代表跳转url |
|||
*/ |
|||
private Integer type; |
|||
/** |
|||
* 按钮文案,建议不超过10个字 |
|||
*/ |
|||
private String text; |
|||
/** |
|||
* 按钮样式,目前可填1~4,不填或错填默认1 |
|||
*/ |
|||
private Integer style; |
|||
/** |
|||
* 按钮key值,用户点击后,会产生回调事件将本参数作为EventKey返回,回调事件会带上该key值,最长支持1024字节,不可重复,button_list.type是0时必填 |
|||
*/ |
|||
private String key; |
|||
/** |
|||
* 跳转事件的url,button_list.type是1时必填 |
|||
*/ |
|||
private String url; |
|||
} |
|||
@ -0,0 +1,74 @@ |
|||
package com.dreamchaser.depository_manage.config.QyWx_template_card; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.xml.bind.annotation.XmlRootElement; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 卡片模板--按钮交互型 |
|||
* |
|||
*/ |
|||
@XmlRootElement |
|||
@Data |
|||
public class TemplateCard_button_interaction { |
|||
/** |
|||
* 模板卡片类型,投票选择型卡片填写"vote_interaction" |
|||
*/ |
|||
|
|||
private String card_type; |
|||
/** |
|||
* 卡片来源样式信息,不需要来源样式可不填写 |
|||
*/ |
|||
private TemplateCard_source source; |
|||
|
|||
/** |
|||
* 卡片右上角更多操作按钮 |
|||
*/ |
|||
private TemplateCard_action_menu action_menu; |
|||
|
|||
/** |
|||
* 一级标题 |
|||
*/ |
|||
private TemplateCard_main_title main_title; |
|||
|
|||
/** |
|||
* 引用文献样式 |
|||
*/ |
|||
private Template_quote_area quote_area; |
|||
|
|||
/** |
|||
* 二级普通文本,建议不超过160个字,(支持id转译) |
|||
*/ |
|||
private String sub_title_text; |
|||
|
|||
|
|||
/** |
|||
* 二级标题+文本列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过6 |
|||
*/ |
|||
private List<TemplateCard_horizontal_content> horizontal_content_list; |
|||
|
|||
|
|||
/** |
|||
* 整体卡片的点击跳转事件 |
|||
*/ |
|||
private TemplateCard_card_action card_action; |
|||
|
|||
/** |
|||
* 任务id,同一个应用任务id不能重复,只能由数字、字母和“_-@”组成,最长128字节 |
|||
*/ |
|||
private String task_id; |
|||
|
|||
|
|||
/** |
|||
* 下拉式的选择器 |
|||
*/ |
|||
private TemplateCard_button_selection button_selection; |
|||
|
|||
/** |
|||
* 按钮列表,列表长度不超过6 |
|||
*/ |
|||
private List<TemplateCard_button> button_list; |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
package com.dreamchaser.depository_manage.config.QyWx_template_card; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.xml.bind.annotation.XmlRootElement; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 下拉式的选择器 |
|||
*/ |
|||
@XmlRootElement |
|||
@Data |
|||
public class TemplateCard_button_selection { |
|||
/** |
|||
* 下拉式的选择器的key,用户提交选项后,会产生回调事件,回调事件会带上该key值表示该题,最长支持1024字节 |
|||
*/ |
|||
private String question_key; |
|||
|
|||
/** |
|||
* 下拉式的选择器左边的标题 |
|||
*/ |
|||
private String title; |
|||
|
|||
/** |
|||
* 选项列表,下拉选项不超过 10 个,最少1个 |
|||
*/ |
|||
private List<TemplateCard_button_selection_option> option_list; |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
package com.dreamchaser.depository_manage.config.QyWx_template_card; |
|||
|
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* 下拉选项 |
|||
*/ |
|||
@Data |
|||
public class TemplateCard_button_selection_option { |
|||
/** |
|||
* 下拉式的选择器选项的id,用户提交后,会产生回调事件,回调事件会带上该id值表示该选项,最长支持128字节,不可重复 |
|||
*/ |
|||
private String id; |
|||
/** |
|||
* 下拉式的选择器选项的文案,建议不超过16个字 |
|||
*/ |
|||
private String text; |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
package com.dreamchaser.depository_manage.config.QyWx_template_card; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.xml.bind.annotation.XmlRootElement; |
|||
|
|||
|
|||
/** |
|||
* 整体卡片的点击跳转事件 |
|||
*/ |
|||
@XmlRootElement |
|||
@Data |
|||
public class TemplateCard_card_action { |
|||
/** |
|||
* 跳转事件类型,0或不填代表不是链接,1 代表跳转url,2 代表打开小程序 |
|||
*/ |
|||
private Integer type; |
|||
|
|||
/** |
|||
* 跳转事件的url,card_action.type是1时必填 |
|||
*/ |
|||
private String url; |
|||
|
|||
/** |
|||
* 跳转事件的小程序的appid,必须是与当前应用关联的小程序,card_action.type是2时必填 |
|||
*/ |
|||
private Integer appid; |
|||
|
|||
/** |
|||
* 跳转事件的小程序的pagepath,card_action.type是2时选填 |
|||
*/ |
|||
private String pagepath; |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
package com.dreamchaser.depository_manage.config.QyWx_template_card; |
|||
|
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* 关键数据样式 |
|||
*/ |
|||
@Data |
|||
public class TemplateCard_emphasis_content { |
|||
/** |
|||
* 关键数据样式的数据内容,建议不超过14个字 |
|||
*/ |
|||
private String title; |
|||
/** |
|||
* 关键数据样式的数据描述内容,建议不超过22个字 |
|||
*/ |
|||
private String desc; |
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
package com.dreamchaser.depository_manage.config.QyWx_template_card; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.xml.bind.annotation.XmlRootElement; |
|||
|
|||
/** |
|||
* 二级标题+文本列表 |
|||
*/ |
|||
@XmlRootElement |
|||
@Data |
|||
public class TemplateCard_horizontal_content { |
|||
/** |
|||
* 链接类型,0或不填代表不是链接,1 代表跳转url,2 代表下载附件,3 代表点击跳转成员详情 |
|||
*/ |
|||
private Integer type; |
|||
|
|||
/** |
|||
* 二级标题,建议不超过5个字 |
|||
*/ |
|||
private String keyname; |
|||
|
|||
/** |
|||
* 二级文本,如果horizontal_content_list.type是2,该字段代表文件名称(要包含文件类型),建议不超过30个字,(支持id转译) |
|||
*/ |
|||
private String value; |
|||
|
|||
/** |
|||
* 链接跳转的url,horizontal_content_list.type是1时必填 |
|||
*/ |
|||
private String url; |
|||
|
|||
/** |
|||
* 附件的media_id,horizontal_content_list.type是2时必填 |
|||
*/ |
|||
private Integer media_id; |
|||
|
|||
|
|||
/** |
|||
* 成员详情的userid,horizontal_content_list.type是3时必填 |
|||
*/ |
|||
private String userid; |
|||
|
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
package com.dreamchaser.depository_manage.config.QyWx_template_card; |
|||
|
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* 跳转指引样式 |
|||
*/ |
|||
@Data |
|||
public class TemplateCard_jump { |
|||
/** |
|||
* 跳转链接样式的文案内容,建议不超过18个字 |
|||
*/ |
|||
private String title; |
|||
/** |
|||
* 跳转链接类型,0或不填代表不是链接,1 代表跳转url,2 代表跳转小程序 |
|||
*/ |
|||
private String type; |
|||
/** |
|||
* 跳转链接的url,jump_list.type是1时必填 |
|||
*/ |
|||
private String url; |
|||
/** |
|||
* 跳转链接的小程序的appid,必须是与当前应用关联的小程序,jump_list.type是2时必填 |
|||
*/ |
|||
private String appid; |
|||
/** |
|||
* 跳转链接的小程序的pagepath,jump_list.type是2时选填 |
|||
*/ |
|||
private String pagepath; |
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
package com.dreamchaser.depository_manage.config.QyWx_template_card; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.xml.bind.annotation.XmlRootElement; |
|||
|
|||
|
|||
/** |
|||
* 一级标题 |
|||
*/ |
|||
@XmlRootElement |
|||
@Data |
|||
public class TemplateCard_main_title { |
|||
/** |
|||
* 一级标题,建议不超过36个字,(支持id转译) |
|||
*/ |
|||
private String title; |
|||
/** |
|||
* 标题辅助信息,建议不超过44个字,(支持id转译) |
|||
*/ |
|||
private String desc; |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
package com.dreamchaser.depository_manage.config.QyWx_template_card; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.xml.bind.annotation.XmlRootElement; |
|||
|
|||
/* |
|||
卡片来源样式信息 |
|||
*/ |
|||
@XmlRootElement |
|||
@Data |
|||
public class TemplateCard_source { |
|||
/** |
|||
* 来源图片的url,来源图片的尺寸建议为72*72 |
|||
*/ |
|||
private String icon_url; |
|||
|
|||
/** |
|||
* 来源图片的描述,建议不超过20个字,(支持id转译) |
|||
*/ |
|||
private String desc; |
|||
|
|||
/** |
|||
* 来源文字的颜色,目前支持:0(默认) 灰色,1 黑色,2 红色,3 绿色 |
|||
*/ |
|||
private Integer desc_color; |
|||
|
|||
} |
|||
@ -0,0 +1,74 @@ |
|||
package com.dreamchaser.depository_manage.config.QyWx_template_card; |
|||
|
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.xml.bind.annotation.XmlRootElement; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 卡片模板--文本通知型 |
|||
*/ |
|||
@XmlRootElement |
|||
@Data |
|||
public class TemplateCard_text_notice { |
|||
/** |
|||
* 模板卡片类型,投票选择型卡片填写"vote_interaction" |
|||
*/ |
|||
|
|||
private String card_type; |
|||
/** |
|||
* 卡片来源样式信息,不需要来源样式可不填写 |
|||
*/ |
|||
private TemplateCard_source source; |
|||
|
|||
/** |
|||
* 卡片右上角更多操作按钮 |
|||
*/ |
|||
private TemplateCard_action_menu action_menu; |
|||
|
|||
/** |
|||
* 一级标题 |
|||
*/ |
|||
private TemplateCard_main_title main_title; |
|||
|
|||
/** |
|||
* 引用文献样式 |
|||
*/ |
|||
private Template_quote_area quote_area; |
|||
|
|||
/** |
|||
* 关键数据样式 |
|||
*/ |
|||
private TemplateCard_emphasis_content emphasis_content; |
|||
|
|||
/** |
|||
* 二级普通文本,建议不超过160个字,(支持id转译) |
|||
*/ |
|||
private String sub_title_text; |
|||
|
|||
|
|||
/** |
|||
* 二级标题+文本列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过6 |
|||
*/ |
|||
private List<TemplateCard_horizontal_content> horizontal_content_list; |
|||
|
|||
/** |
|||
* 跳转指引样式的列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过3 |
|||
*/ |
|||
private List<TemplateCard_jump> jump_list; |
|||
|
|||
|
|||
/** |
|||
* 整体卡片的点击跳转事件 |
|||
*/ |
|||
private TemplateCard_card_action card_action; |
|||
|
|||
/** |
|||
* 任务id,同一个应用任务id不能重复,只能由数字、字母和“_-@”组成,最长128字节 |
|||
*/ |
|||
private String task_id; |
|||
|
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
package com.dreamchaser.depository_manage.config.QyWx_template_card; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.xml.bind.annotation.XmlRootElement; |
|||
|
|||
/** |
|||
* 引用文献样式 |
|||
*/ |
|||
@XmlRootElement |
|||
@Data |
|||
public class Template_quote_area { |
|||
/** |
|||
* 引用文献样式区域点击事件,0或不填代表没有点击事件,1 代表跳转url,2 代表跳转小程序 |
|||
*/ |
|||
private Integer type; |
|||
/** |
|||
* 点击跳转的url,quote_area.type是1时必填 |
|||
*/ |
|||
private String url; |
|||
/** |
|||
* 点击跳转的小程序的appid,必须是与当前应用关联的小程序,quote_area.type是2时必填 |
|||
*/ |
|||
private Integer appid; |
|||
/** |
|||
* 点击跳转的小程序的pagepath,quote_area.type是2时选填 |
|||
*/ |
|||
private String pagepath; |
|||
/** |
|||
* 引用文献样式的标题 |
|||
*/ |
|||
private String title; |
|||
/** |
|||
* 引用文献样式的引用文案 |
|||
*/ |
|||
private String quote_text; |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
package com.dreamchaser.depository_manage.config.QyWx_template_card; |
|||
|
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* 文本卡片信息中的消息类 |
|||
*/ |
|||
@Data |
|||
public class TextCardContent { |
|||
// 标题,不超过128个字节,超过会自动截断(支持id转译)
|
|||
private String title; |
|||
// 描述,不超过512个字节,超过会自动截断(支持id转译)
|
|||
private String description; |
|||
// 点击后跳转的链接。最长2048字节,请确保包含了协议头(http/https)
|
|||
private String url; |
|||
//按钮文字。 默认为“详情”, 不超过4个文字,超过自动截断。
|
|||
private String btntxt; |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
package com.dreamchaser.depository_manage.config.QyWx_template_card; |
|||
|
|||
|
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* 文本通知型 |
|||
*/ |
|||
|
|||
@Data |
|||
public class TextNotice extends BaseMessage{ |
|||
// 模板卡片
|
|||
private TemplateCard_text_notice template_card; |
|||
// 否 表示是否是保密消息,0表示否,1表示是,默认0
|
|||
private int safe; |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
package com.dreamchaser.depository_manage.config.QyWx_template_card; |
|||
|
|||
import lombok.Data; |
|||
|
|||
@Data |
|||
public class TextTemplateCard extends BaseMessage { |
|||
private TextCardContent textcard; |
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
package com.dreamchaser.depository_manage.config; |
|||
|
|||
import org.redisson.Redisson; |
|||
import org.redisson.api.RedissonClient; |
|||
import org.redisson.config.Config; |
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.context.annotation.Configuration; |
|||
|
|||
import java.io.IOException; |
|||
|
|||
|
|||
/** |
|||
* redission的简单配置 |
|||
*/ |
|||
@Configuration |
|||
public class RedissionConfig { |
|||
|
|||
@Bean |
|||
public RedissonClient redisson() throws IOException { |
|||
// 本例子使用的是yaml格式的配置文件,读取使用Config.fromYAML,如果是Json文件,则使用Config.fromJSON
|
|||
Config config = Config.fromYAML(RedissionConfig.class.getClassLoader().getResource("redisson-config.yml")); |
|||
return Redisson.create(config); |
|||
} |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
package com.dreamchaser.depository_manage.config; |
|||
|
|||
import com.dreamchaser.depository_manage.intercepter.UserInterceptor; |
|||
import org.springframework.context.annotation.Configuration; |
|||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; |
|||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
|||
|
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
|
|||
|
|||
/** |
|||
* 路径配置 |
|||
*/ |
|||
@Configuration |
|||
public class WebMvcConfig implements WebMvcConfigurer { |
|||
|
|||
@Override |
|||
public void addInterceptors(InterceptorRegistry registry) { |
|||
registry.addInterceptor(new UserInterceptor()) |
|||
.addPathPatterns("/**") |
|||
.excludePathPatterns("/webSocket/{number}","/login", "/register", "/sendCode", "/error","/callback","/QyWxLogin","/getMaterialAll","/approvalcallback","/identityVerify") |
|||
.excludePathPatterns("classpath:/static/**") |
|||
.excludePathPatterns("/static/**"); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
@ -0,0 +1,22 @@ |
|||
package com.dreamchaser.depository_manage.config; |
|||
|
|||
|
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.context.annotation.Configuration; |
|||
import org.springframework.web.socket.server.standard.ServerEndpointExporter; |
|||
|
|||
/** |
|||
* webSocket配置项,线上暂没实现 |
|||
*/ |
|||
@Configuration |
|||
public class WebSocketConfig { |
|||
/** |
|||
* 注入ServerEndpointExporter, |
|||
* 这个bean会自动注册使用了@ServerEndpoint注解声明的Websocket endpoint |
|||
*/ |
|||
@Bean |
|||
public ServerEndpointExporter serverEndpointExporter() { |
|||
return new ServerEndpointExporter(); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,152 @@ |
|||
package com.dreamchaser.depository_manage.controller; |
|||
|
|||
import com.dreamchaser.depository_manage.entity.BusinessType; |
|||
import com.dreamchaser.depository_manage.entity.UserByPort; |
|||
import com.dreamchaser.depository_manage.exception.MyException; |
|||
import com.dreamchaser.depository_manage.pojo.RestResponse; |
|||
import com.dreamchaser.depository_manage.security.pool.AuthenticationTokenPool; |
|||
import com.dreamchaser.depository_manage.service.BusinessTypeService; |
|||
import com.dreamchaser.depository_manage.utils.CrudUtil; |
|||
import com.dreamchaser.depository_manage.utils.ObjectFormatUtil; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Controller; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
|
|||
/** |
|||
* 用于页面类型的控制类 |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("/businessType") |
|||
public class BusinessTypeController { |
|||
@Autowired |
|||
private BusinessTypeService businessTypeService; |
|||
|
|||
/** |
|||
* 添加一条新的业务类型数据 |
|||
* |
|||
* @param map 带插入数据 |
|||
* @param request |
|||
* @return |
|||
*/ |
|||
@PostMapping("/addBusinessType") |
|||
public RestResponse addBusinessType(@RequestBody Map<String, Object> map, HttpServletRequest request) { |
|||
String usertoken = request.getHeader("user-token"); |
|||
String userkey = request.getHeader("user-key"); |
|||
if (usertoken == null) { |
|||
usertoken = (String) request.getSession().getAttribute("userToken"); |
|||
userkey = (String) request.getSession().getAttribute("userKey"); |
|||
} |
|||
// 获取当前登录用户
|
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(usertoken); |
|||
map.put("createUid", userToken.getId()); |
|||
return CrudUtil.insertHandle(businessTypeService.addBusinessType(map), 1); |
|||
} |
|||
|
|||
/** |
|||
* 修改一条业务类型数据 |
|||
* |
|||
* @param map 待修改数据 |
|||
* @param request |
|||
* @return |
|||
*/ |
|||
@PostMapping("/updateBusinessType") |
|||
public RestResponse updateBusinessType(@RequestBody Map<String, Object> map, HttpServletRequest request) { |
|||
String usertoken = request.getHeader("user-token"); |
|||
String userkey = request.getHeader("user-key"); |
|||
if (usertoken == null) { |
|||
usertoken = (String) request.getSession().getAttribute("userToken"); |
|||
userkey = (String) request.getSession().getAttribute("userKey"); |
|||
} |
|||
// 获取当前登录用户
|
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(usertoken); |
|||
map.put("updateUid", userToken.getId()); |
|||
return CrudUtil.updateHandle(businessTypeService.updateBusinessType(map), 1); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 删除业务类型数据(软删除) |
|||
* |
|||
* @param map 待删除数据 |
|||
* @param request |
|||
* @return |
|||
*/ |
|||
@PostMapping("/deleteBusinessType") |
|||
public RestResponse deleteBusinessType(@RequestBody Map<String, Object> map, HttpServletRequest request) { |
|||
String usertoken = request.getHeader("user-token"); |
|||
String userkey = request.getHeader("user-key"); |
|||
if (usertoken == null) { |
|||
usertoken = (String) request.getSession().getAttribute("userToken"); |
|||
userkey = (String) request.getSession().getAttribute("userKey"); |
|||
} |
|||
// 获取当前登录用户
|
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(usertoken); |
|||
map.put("state", 3); |
|||
map.put("updateUid", userToken.getId()); |
|||
if (map.containsKey("id")) { |
|||
return CrudUtil.updateHandle(businessTypeService.updateBusinessTypeStateById(map), 1); |
|||
|
|||
} else if (map.containsKey("ids")) { |
|||
Integer count = ObjectFormatUtil.toInteger(map.get("count")); |
|||
return CrudUtil.updateHandle(businessTypeService.updateBusinessTypeStateByIds(map), count); |
|||
} else { |
|||
throw new MyException("所需请求参数缺失!"); |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 修改业务类型数据状态(启用禁用) |
|||
* |
|||
* @param map 待修改数据 |
|||
* @param request |
|||
* @return |
|||
*/ |
|||
@PostMapping("/forbiddenBusinessType") |
|||
public RestResponse forbiddenBusinessType(@RequestBody Map<String, Object> map, HttpServletRequest request) { |
|||
String usertoken = request.getHeader("user-token"); |
|||
String userkey = request.getHeader("user-key"); |
|||
if (usertoken == null) { |
|||
usertoken = (String) request.getSession().getAttribute("userToken"); |
|||
userkey = (String) request.getSession().getAttribute("userKey"); |
|||
} |
|||
// 获取当前登录用户
|
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(usertoken); |
|||
if (map.containsKey("state")) { |
|||
map.put("state", 1); |
|||
} else { |
|||
map.put("state", 2); |
|||
} |
|||
map.put("updateUid", userToken.getId()); |
|||
if (map.containsKey("id")) { |
|||
return CrudUtil.updateHandle(businessTypeService.updateBusinessTypeStateById(map), 1); |
|||
|
|||
} else if (map.containsKey("ids")) { |
|||
Integer count = ObjectFormatUtil.toInteger(map.get("count")); |
|||
return CrudUtil.updateHandle(businessTypeService.updateBusinessTypeStateByIds(map), count); |
|||
} else { |
|||
throw new MyException("所需请求参数缺失!"); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 根据条件查询业务类型数据 |
|||
* @param map 带查询数据 |
|||
* @param request |
|||
* @return |
|||
*/ |
|||
@GetMapping("/findBusinessType") |
|||
public RestResponse findBusinessType(@RequestParam Map<String, Object> map, HttpServletRequest request) { |
|||
List<BusinessType> businessTypeByCondition = businessTypeService.findBusinessTypeByCondition(map); |
|||
Integer businessTypeCountByCondition = businessTypeService.findBusinessTypeCountByCondition(map); |
|||
return new RestResponse(businessTypeByCondition, businessTypeCountByCondition, 200); |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,576 @@ |
|||
package com.dreamchaser.depository_manage.controller; |
|||
|
|||
import com.alibaba.fastjson.JSONArray; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.dreamchaser.depository_manage.config.PublicConfig; |
|||
import com.dreamchaser.depository_manage.entity.*; |
|||
import com.dreamchaser.depository_manage.exception.MyException; |
|||
import com.dreamchaser.depository_manage.pojo.*; |
|||
import com.dreamchaser.depository_manage.security.pool.AuthenticationTokenPool; |
|||
import com.dreamchaser.depository_manage.service.*; |
|||
import com.dreamchaser.depository_manage.utils.*; |
|||
import org.apache.http.protocol.HTTP; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import java.io.IOException; |
|||
import java.util.ArrayList; |
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
|
|||
/** |
|||
* 用于获取行政组织的控制器 |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("/company") |
|||
public class CompanyController { |
|||
|
|||
@Autowired |
|||
private CompanyService companyService; |
|||
|
|||
@Autowired |
|||
private RoleService roleService; |
|||
|
|||
@Autowired |
|||
private DepositoryService depositoryService; |
|||
|
|||
@Autowired |
|||
private ConstructionUnitService constructionUnitService; |
|||
|
|||
@Autowired |
|||
private PostService postService; |
|||
|
|||
|
|||
|
|||
|
|||
/** |
|||
* 查询组织架构 |
|||
* |
|||
* @param map 查询条件 |
|||
* @param request 请求体 |
|||
* @return |
|||
*/ |
|||
@PostMapping("/allCompanyByParent") |
|||
public RestResponse findCompanyByNoParent(@RequestParam Map<String, Object> map, HttpServletRequest request) { |
|||
String token = request.getHeader("user-token"); |
|||
String key = request.getHeader("user-key"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
key = (String) request.getSession().getAttribute("userKey"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
String url = PublicConfig.external_url + "/org/govlist"; |
|||
Object page = map.get("page"); |
|||
Object pagesize = map.get("size"); |
|||
String superior = (String) map.get("superior"); |
|||
Integer level = ObjectFormatUtil.toInteger(map.get("level")); |
|||
if ("".equals(superior)) { |
|||
superior = "313"; |
|||
} |
|||
map.put("page", ObjectFormatUtil.toInteger(page)); |
|||
map.put("pagesize", ObjectFormatUtil.toInteger(pagesize)); |
|||
map.put("superior", superior); |
|||
map.put("level", level); |
|||
map.put("state", 1); |
|||
String jsonString = JSONObject.toJSONString(map); |
|||
JSONObject paramObject = JSONObject.parseObject(jsonString); |
|||
String post = null; |
|||
try { |
|||
post = HttpUtils.send(url, paramObject, HTTP.UTF_8,key, token); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
JSONObject jsonObject = JSONObject.parseObject(post); |
|||
JSONObject data = (JSONObject) jsonObject.get("data"); |
|||
JSONArray list = (JSONArray) data.get("list"); |
|||
if (list == null) { |
|||
list = new JSONArray(); |
|||
} |
|||
Integer total = ObjectFormatUtil.toInteger(data.get("total")); |
|||
List<AdministrationP> administrationPList = new ArrayList<>(); |
|||
for (Object o : list) { |
|||
Administration administration = JSONObject.toJavaObject((JSONObject) o, Administration.class); |
|||
AdministrationP administrationP = new AdministrationP(administration); |
|||
administrationPList.add(administrationP); |
|||
} |
|||
return new RestResponse(administrationPList, total, 200); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于查询所有公司 |
|||
* @param request |
|||
* @return |
|||
*/ |
|||
@GetMapping("/findAllCompany") |
|||
public RestResponse findAllCompany(HttpServletRequest request){ |
|||
String token = request.getHeader("user-token"); |
|||
String userKey = request.getHeader("user-key"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
userKey = (String) request.getSession().getAttribute("userKey"); |
|||
} |
|||
Map<String, Object> administration = PublicConfig.findAdministration(userKey,token); |
|||
List<AdministrationP> administrationPList = ObjectFormatUtil.objToList(administration.get("administrationPList"),AdministrationP.class); |
|||
return new RestResponse(administrationPList); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 获取当前公司下的部门 |
|||
* @param company |
|||
* @param request |
|||
* @return |
|||
*/ |
|||
@GetMapping("/findPostByCompany") |
|||
public RestResponse findPostByCompany(@RequestParam("company") String company, HttpServletRequest request) { |
|||
String token = request.getHeader("user-token"); |
|||
String userKey = request.getHeader("user-key"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
userKey = (String) request.getSession().getAttribute("userKey"); |
|||
} |
|||
List<AdministrationP> administrationPList = PublicConfig.findCompanyBySuperior(company, token,userKey); |
|||
int size = administrationPList.size(); |
|||
return new RestResponse(administrationPList, size, 200); |
|||
} |
|||
|
|||
/** |
|||
* 根据条件查询公司 |
|||
* |
|||
* @param map 查询条件 |
|||
* @return 返回结果 |
|||
*/ |
|||
@PostMapping("/companyByCondition") |
|||
public RestResponse findcompanyByCondition(@RequestParam Map<String, Object> map, HttpServletRequest request) { |
|||
String token = request.getHeader("user-token"); |
|||
String key = request.getHeader("user-key"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
key = (String) request.getSession().getAttribute("userKey"); |
|||
} |
|||
String url = PublicConfig.external_url + "/org/govlist"; |
|||
if (map.containsKey("state")) { |
|||
Object state = map.get("state"); |
|||
map.put("state", ObjectFormatUtil.toInteger(state)); |
|||
} |
|||
Object page = map.get("page"); |
|||
Object pagesize = map.get("size"); |
|||
map.put("page", ObjectFormatUtil.toInteger(page)); |
|||
map.put("pagesize", ObjectFormatUtil.toInteger(pagesize)); |
|||
String jsonString = JSONObject.toJSONString(map); |
|||
JSONObject paramObject = JSONObject.parseObject(jsonString); |
|||
String post = null; |
|||
try { |
|||
post = HttpUtils.send(url, paramObject, HTTP.UTF_8, key,token); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
JSONObject jsonObject = JSONObject.parseObject(post); |
|||
JSONObject data = (JSONObject) jsonObject.get("data"); |
|||
JSONArray list = (JSONArray) data.get("list"); |
|||
if (list == null) { |
|||
list = new JSONArray(); |
|||
} |
|||
Integer total = ObjectFormatUtil.toInteger(data.get("total")); |
|||
List<AdministrationP> administrationPList = new ArrayList<>(); |
|||
for (int i = 0; i < list.size(); i++) { |
|||
Administration administration = JSONObject.toJavaObject((JSONObject) list.get(i), Administration.class); |
|||
AdministrationP administrationP = new AdministrationP(administration); |
|||
administrationPList.add(administrationP); |
|||
} |
|||
return new RestResponse(list, total, 200); |
|||
} |
|||
|
|||
/** |
|||
* 根据条件查询岗位 |
|||
* |
|||
* @param map 查询条件 |
|||
* @return |
|||
*/ |
|||
@PostMapping("/allPostByOrganization") |
|||
public RestResponse allPostByParent(@RequestParam Map<String, Object> map, HttpServletRequest request) { |
|||
String token = request.getHeader("user-token"); |
|||
String key = request.getHeader("user-key"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
key = (String) request.getSession().getAttribute("userKey"); |
|||
} |
|||
String url = PublicConfig.external_url + "/org/positionlist"; |
|||
Object page = map.get("page"); |
|||
Object pagesize = map.get("size"); |
|||
map.put("page", ObjectFormatUtil.toInteger(page)); |
|||
map.put("pagesize", ObjectFormatUtil.toInteger(pagesize)); |
|||
String jsonString = JSONObject.toJSONString(map); |
|||
JSONObject paramObject = JSONObject.parseObject(jsonString); |
|||
String post = null; |
|||
try { |
|||
post = HttpUtils.send(url, paramObject, HTTP.UTF_8, key,token); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
JSONObject jsonObject = JSONObject.parseObject(post); |
|||
JSONObject data = (JSONObject) jsonObject.get("data"); |
|||
JSONArray list = (JSONArray) data.get("list"); |
|||
if (list == null) { |
|||
list = new JSONArray(); |
|||
} |
|||
Integer total = ObjectFormatUtil.toInteger(data.get("total")); |
|||
List<PostP> postList = new ArrayList<>(); |
|||
for (int i = 0; i < list.size(); i++) { |
|||
Post object = JSONObject.toJavaObject((JSONObject) list.get(i), Post.class); |
|||
PostP postP = new PostP(object); |
|||
List<RoleAndDepository> depositoryAndRole = roleService.findDepositoryAndRole(postP.getId()); |
|||
if (depositoryAndRole != null) { |
|||
StringBuilder Depository = new StringBuilder(); |
|||
for (int j = 0; j < depositoryAndRole.size(); j++) { |
|||
String depositoryName = depositoryAndRole.get(i).getDepositoryName(); |
|||
if (depositoryName == null) { |
|||
depositoryName = ""; |
|||
} |
|||
Depository.append(depositoryName).append(" "); |
|||
} |
|||
postP.setDepositoryName(Depository.toString()); |
|||
} else { |
|||
postP.setDepositoryName(""); |
|||
} |
|||
postList.add(postP); |
|||
} |
|||
return new RestResponse(postList, total, 200); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 给岗位设置权限 |
|||
* |
|||
* @param map 条件 |
|||
* @return 设置结果 |
|||
*/ |
|||
@PostMapping("/post_role") |
|||
public RestResponse addUser(@RequestBody Map<String, Object> map, HttpServletRequest request) { |
|||
String token = request.getHeader("user-token"); |
|||
String userKey = request.getHeader("user-key"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
userKey = (String) request.getSession().getAttribute("userKey"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
Map<String, Object> userParam = new HashMap<>(); |
|||
userParam.put("position", ObjectFormatUtil.toInteger(map.get("userid"))); |
|||
List<UserByPort> userByPortList = PublicConfig.FindUserByMap(userParam, userKey,token); |
|||
Integer success = 0; |
|||
if (map.containsKey("depositoryId")) { |
|||
for (UserByPort userByPort : userByPortList) { |
|||
int emptype = userByPort.getEmptype(); |
|||
if(emptype > 10){ |
|||
continue; |
|||
} |
|||
Map<String, Object> param = new HashMap<>(); |
|||
param.put("userId", userByPort.getId()); |
|||
param.put("depositoryId", map.get("depositoryId")); |
|||
param.put("classes", map.get("classes")); |
|||
List<RoleAndDepository> roleAndDepositoryByCondition = roleService.findRoleAndDepositoryByCondition(param); |
|||
if (roleAndDepositoryByCondition.size() <= 0) { |
|||
Map<String, Object> insert = new HashMap<>(); |
|||
insert.put("classes", map.get("classes")); |
|||
insert.put("authority", 0); |
|||
insert.put("depositoryId", map.get("depositoryId")); |
|||
insert.put("userid", userByPort.getId()); |
|||
success += roleService.addUserOrPostRoleAndDepository(insert); |
|||
} |
|||
} |
|||
} else { |
|||
List<Depository> depositoryAll = depositoryService.findDepositoryAll(); |
|||
for (Depository depository : depositoryAll) { |
|||
for (UserByPort userByPort : userByPortList) { |
|||
Map<String, Object> param = new HashMap<>(); |
|||
param.put("userId", userByPort.getId()); |
|||
param.put("depositoryId", depository.getId()); |
|||
param.put("classes", map.get("classes")); |
|||
List<RoleAndDepository> roleAndDepositoryByCondition = roleService.findRoleAndDepositoryByCondition(param); |
|||
if (roleAndDepositoryByCondition.size() <= 0) { |
|||
Map<String, Object> insert = new HashMap<>(); |
|||
insert.put("classes", map.get("classes")); |
|||
insert.put("authority", 0); |
|||
insert.put("depositoryId", depository.getId()); |
|||
insert.put("userid", userByPort.getId()); |
|||
success += roleService.addUserOrPostRoleAndDepository(insert); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
return CrudUtil.insertHandle(success, success); |
|||
} |
|||
|
|||
/** |
|||
* 修改岗位的权限 |
|||
* |
|||
* @param map 修改条件 |
|||
* @return |
|||
*/ |
|||
@PostMapping("/postRole_edit") |
|||
public RestResponse editPostRole(@RequestBody Map<String, Object> map) { |
|||
Map<String, Object> userParam = new HashMap<>(); |
|||
Integer oldDepository = ObjectFormatUtil.toInteger(map.get("oldDepository")); |
|||
Integer depositoryId = ObjectFormatUtil.toInteger(map.get("depositoryId")); |
|||
userParam.put("position", ObjectFormatUtil.toInteger(map.get("userid"))); |
|||
Map<String, Object> param = new HashMap<>(); |
|||
param.put("depositoryId", oldDepository); |
|||
param.put("classes", 2); |
|||
List<RoleAndDepository> roleAndDepositoryByCondition = roleService.findRoleAndDepositoryByCondition(param); |
|||
Integer success = 0; |
|||
for (int i = 0; i < roleAndDepositoryByCondition.size(); i++) { |
|||
RoleAndDepository roleAndDepository = roleAndDepositoryByCondition.get(i); |
|||
Map<String, Object> update = new HashMap<>(); |
|||
update.put("roleId", roleAndDepository.getId()); |
|||
update.put("depositoryId", depositoryId); |
|||
update.put("classes", 2); |
|||
success += roleService.UpdateRoleAndDepositoryById(update); |
|||
} |
|||
return CrudUtil.insertHandle(success, roleAndDepositoryByCondition.size()); |
|||
} |
|||
|
|||
/** |
|||
* 根据主键删除权限类型 |
|||
* |
|||
* @param map 删除条件 |
|||
* @return |
|||
*/ |
|||
@PostMapping("/postRole_del") |
|||
public RestResponse deleteRoleAndDepository(@RequestBody Map<String, Object> map) { |
|||
if (map.containsKey("depositoryId")) { |
|||
Integer depositoryId = ObjectFormatUtil.toInteger(map.get("depositoryId")); |
|||
Map<String, Object> param = new HashMap<>(); |
|||
param.put("depositoryId", depositoryId); |
|||
param.put("classes", map.get("classes")); |
|||
List<RoleAndDepository> roleAndDepositoryByCondition = roleService.findRoleAndDepositoryByCondition(param); |
|||
Integer success = 0; |
|||
for (RoleAndDepository roleAndDepository : roleAndDepositoryByCondition) { |
|||
success += roleService.deleteRoleAndDepositoryById(roleAndDepository.getId()); |
|||
} |
|||
return CrudUtil.insertHandle(success, roleAndDepositoryByCondition.size()); |
|||
} else if (map.containsKey("depositoryIds")) { |
|||
Integer num = 0; |
|||
List<Integer> depositoryIds = ObjectFormatUtil.objToList(map.get("depositoryIds"),Integer.class); |
|||
Integer success = 0; |
|||
int total = 0; |
|||
for (Integer depositoryId : depositoryIds) { |
|||
Map<String, Object> param = new HashMap<>(); |
|||
param.put("depositoryId", depositoryId); |
|||
param.put("classes", map.get("classes")); |
|||
List<RoleAndDepository> roleAndDepositoryByCondition = roleService.findRoleAndDepositoryByCondition(param); |
|||
total += roleAndDepositoryByCondition.size(); |
|||
for (RoleAndDepository roleAndDepository : roleAndDepositoryByCondition) { |
|||
success += roleService.deleteRoleAndDepositoryById(roleAndDepository.getId()); |
|||
} |
|||
} |
|||
return CrudUtil.insertHandle(success, total); |
|||
} else { |
|||
throw new MyException("所需请求参数缺失!"); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 查询岗位对应的权限 |
|||
* |
|||
* @param map 要查询的调剂 |
|||
* @return |
|||
*/ |
|||
@GetMapping("/findPostRole") |
|||
public RestResponse findPostRole(@RequestParam Map<String, Object> map, HttpServletRequest request) { |
|||
String token = request.getHeader("user-token"); |
|||
String userKey = request.getHeader("user-key"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
userKey = (String) request.getSession().getAttribute("userKey"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
Map<String, Object> userParam = new HashMap<>(); |
|||
Long postId = ObjectFormatUtil.toLong(map.get("postId")); |
|||
userParam.put("position", postId); |
|||
List<UserByPort> userByPortList = PublicConfig.FindUserByMap(userParam, userKey,token); |
|||
Post postById = postService.findPostById(postId); |
|||
List<RoleAndDepository> roleAndDepositoryByCondition = new ArrayList<>(); |
|||
if (userByPortList.size() != 0) { |
|||
Map<String, Object> param = new HashMap<>(); |
|||
param.put("classes", map.get("classes")); |
|||
param.put("userId", userByPortList.get(0).getId()); |
|||
roleAndDepositoryByCondition = roleService.findRoleAndDepositoryByCondition(param); |
|||
} |
|||
List<PostP> postPS = new ArrayList<>(); |
|||
for (RoleAndDepository roleAndDepository : roleAndDepositoryByCondition) { |
|||
PostP pp = new PostP(postById); |
|||
pp.setDepositoryName(roleAndDepository.getDepositoryName()); |
|||
pp.setDepositoryId(roleAndDepository.getDepositoryId()); |
|||
postPS.add(pp); |
|||
} |
|||
return new RestResponse(postPS, postPS.size(), 200); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于进行选择负责人 |
|||
* |
|||
* @param request |
|||
* @return |
|||
*/ |
|||
@GetMapping("/managerTreeMenus") |
|||
public RestResponse InitTreeMenus(HttpServletRequest request) { |
|||
List<Object> list = new ArrayList<>(); |
|||
String token = request.getHeader("user-token"); |
|||
String userKey = request.getHeader("user-key"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
userKey = (String) request.getSession().getAttribute("userKey"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
list = companyService.InitTreeMenusForHearder(userToken,userKey,token); |
|||
return new RestResponse(list); |
|||
} |
|||
|
|||
/** |
|||
* 用于构造当前用户可见的部门树 |
|||
* @return |
|||
*/ |
|||
@GetMapping("/postTreeMenus") |
|||
public RestResponse postTreeMenus(HttpServletRequest request){ |
|||
List<Object> list = new ArrayList<>(); |
|||
String token = request.getHeader("user-token"); |
|||
String userKey = request.getHeader("user-key"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
userKey = (String) request.getSession().getAttribute("userKey"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
list = companyService.buildPostTree(userToken,userKey,token); |
|||
return new RestResponse(list); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于构造当前用户可见的部门树 |
|||
* @return |
|||
*/ |
|||
@GetMapping("/constructionUnitTree") |
|||
public RestResponse constructionUnitTree(HttpServletRequest request){ |
|||
List<Object> list = new ArrayList<>(); |
|||
list = companyService.buildConstructionUnitTree(); |
|||
return new RestResponse(list); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
/** |
|||
* 用于获取企业微信通讯录下的结构 |
|||
* |
|||
* @param request |
|||
* @return |
|||
*/ |
|||
@GetMapping("/departmentTreeMenus") |
|||
public RestResponse departmentTreeMenus(HttpServletRequest request) { |
|||
List<Object> list = new ArrayList<>(); |
|||
String token = request.getHeader("user-token"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
String header = request.getHeader("user-agent"); |
|||
String crypt = Md5.crypt(header); |
|||
list = companyService.BuildQyWxAdministrationTreeMenus(userToken, crypt); |
|||
return new RestResponse(list); |
|||
} |
|||
|
|||
/** |
|||
* 获取行政组织与岗位树 |
|||
*/ |
|||
@GetMapping("/getOrgAndPostThree") |
|||
public RestResponse getOrgAndPostThree(HttpServletRequest request){ |
|||
String token = request.getHeader("user-token"); |
|||
String userKey = request.getHeader("user-key"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
userKey = (String) request.getSession().getAttribute("userKey"); |
|||
} |
|||
return new RestResponse(companyService.BuildOrgAndPostThree(userKey,token)); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于创建施工单位 |
|||
* |
|||
* @param map 创建数据 |
|||
* @return |
|||
*/ |
|||
@PostMapping("/constructionUnitAdd") |
|||
public RestResponse constructionUnitAdd(@RequestBody Map<String, Object> map) { |
|||
return CrudUtil.insertHandle(constructionUnitService.addConstructionUnit(map), 1); |
|||
} |
|||
|
|||
/** |
|||
* 用于根据条件查询施工单位 |
|||
* |
|||
* @param map 查询条件 |
|||
* @return |
|||
*/ |
|||
@GetMapping("/allConstructionUnit") |
|||
public RestResponse allConstructionUnit(@RequestParam Map<String, Object> map) { |
|||
List<ConstructionUnit> constructionUnitByCondition = constructionUnitService.findConstructionUnitByCondition(map); |
|||
return new RestResponse(constructionUnitByCondition, constructionUnitService.findConstructionUnitCountByCondition(map), 200); |
|||
} |
|||
|
|||
/** |
|||
* 用于修改施工单位信息 |
|||
* |
|||
* @param map 修改数据 |
|||
* @return |
|||
*/ |
|||
@PostMapping("/ConstructionUnitEdit") |
|||
public RestResponse ConstructionUnitEdit(@RequestBody Map<String, Object> map) { |
|||
return CrudUtil.updateHandle(constructionUnitService.updateConstructionUnit(map), 1); |
|||
} |
|||
|
|||
/** |
|||
* 用于修改施工单位的状态 |
|||
* |
|||
* @param map 修改数据 |
|||
* @return |
|||
*/ |
|||
@PostMapping("/ConstructionUnitStateEdit") |
|||
public RestResponse ConstructionUnitStateEdit(@RequestBody Map<String, Object> map) { |
|||
if (!map.containsKey("state")) { |
|||
map.put("state", 2); |
|||
} |
|||
return CrudUtil.updateHandle(constructionUnitService.updateConstructionUnitState(map), 1); |
|||
} |
|||
|
|||
|
|||
@PostMapping("/ConstructionUnitDel") |
|||
public RestResponse ConstructionUnitDel(@RequestBody Map<String, Object> map) { |
|||
Integer result = 0; |
|||
int count = 1; |
|||
map.put("state", 3); |
|||
if (map.containsKey("id")) { |
|||
// 如果是删除一个
|
|||
|
|||
result += constructionUnitService.updateConstructionUnitState(map); |
|||
} else if (map.containsKey("ids")) { |
|||
// 如果删除多个
|
|||
|
|||
// 获取要删除的id
|
|||
List<Object> ids = ObjectFormatUtil.objToList(map.get("ids"),Object.class); |
|||
count = ids.size(); |
|||
map.remove("ids"); |
|||
for (Object id : ids |
|||
) { |
|||
map.put("id", id); |
|||
result += constructionUnitService.updateConstructionUnitState(map); |
|||
} |
|||
} |
|||
return CrudUtil.deleteHandle(result, count); |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -0,0 +1,214 @@ |
|||
package com.dreamchaser.depository_manage.controller; |
|||
|
|||
import com.dreamchaser.depository_manage.config.PublicConfig; |
|||
import com.dreamchaser.depository_manage.entity.UserByPort; |
|||
import com.dreamchaser.depository_manage.security.pool.AuthenticationTokenPool; |
|||
import com.dreamchaser.depository_manage.utils.DeviceUtil; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import javax.servlet.http.HttpServletResponse; |
|||
import java.io.*; |
|||
import java.net.URLEncoder; |
|||
|
|||
@RestController |
|||
@RequestMapping("/download") |
|||
public class DownLoadFileController { |
|||
|
|||
/** |
|||
* @param response |
|||
* @功能描述 下载文件: |
|||
*/ |
|||
@RequestMapping("/zipDownload") |
|||
public void zipDownload(HttpServletRequest request, HttpServletResponse response) { |
|||
try { |
|||
String path = "static/upload/PrintServer.zip"; |
|||
String fileName = "PrintServer.zip"; |
|||
response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8")); |
|||
response.setContentType("content-type:octet-stream"); |
|||
/* .getClassLoader() 方法是在静态文件路径添加一个/ */ |
|||
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(path); |
|||
OutputStream outputStream = response.getOutputStream(); |
|||
try { |
|||
byte[] buffer = new byte[1024]; |
|||
int len; |
|||
assert inputStream != null; |
|||
while ((len = inputStream.read(buffer)) != -1) { /* 将流中内容写出去 .*/ |
|||
outputStream.write(buffer, 0, len); |
|||
} |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} finally { |
|||
assert inputStream != null; |
|||
inputStream.close(); |
|||
outputStream.close(); |
|||
} |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* @param response |
|||
* @功能描述 下载物料导入模板: |
|||
*/ |
|||
@RequestMapping("/materialImportDownload") |
|||
public void materialImportDownload(HttpServletRequest request, HttpServletResponse response) { |
|||
try { |
|||
|
|||
String path = "static/upload/materialImport.xlsx"; |
|||
|
|||
String fileName = "materialImport.xlsx"; |
|||
response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8")); |
|||
response.setContentType("content-type:octet-stream"); |
|||
/* .getClassLoader() 方法是在静态文件路径添加一个/ */ |
|||
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(path); |
|||
OutputStream outputStream = response.getOutputStream(); |
|||
try { |
|||
byte[] buffer = new byte[1024]; |
|||
int len; |
|||
assert inputStream != null; |
|||
while ((len = inputStream.read(buffer)) != -1) { /* 将流中内容写出去 .*/ |
|||
outputStream.write(buffer, 0, len); |
|||
} |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} finally { |
|||
assert inputStream != null; |
|||
inputStream.close(); |
|||
outputStream.close(); |
|||
} |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* @param response |
|||
* @功能描述 下载物料类型导入模板: |
|||
*/ |
|||
@RequestMapping("/materialTypeImportDownload") |
|||
public void materialTypeImportDownload(HttpServletRequest request, HttpServletResponse response) { |
|||
try { |
|||
|
|||
String path = "static/upload/materialTypeImport.xlsx"; |
|||
|
|||
String fileName = "materialTypeImport.xlsx"; |
|||
response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8")); |
|||
response.setContentType("content-type:octet-stream"); |
|||
/* .getClassLoader() 方法是在静态文件路径添加一个/ */ |
|||
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(path); |
|||
OutputStream outputStream = response.getOutputStream(); |
|||
try { |
|||
byte[] buffer = new byte[1024]; |
|||
int len; |
|||
assert inputStream != null; |
|||
while ((len = inputStream.read(buffer)) != -1) { /* 将流中内容写出去 .*/ |
|||
outputStream.write(buffer, 0, len); |
|||
} |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} finally { |
|||
assert inputStream != null; |
|||
inputStream.close(); |
|||
outputStream.close(); |
|||
} |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* @param response |
|||
* @功能描述 下载库存导入模板: |
|||
*/ |
|||
@RequestMapping("/inventoryImportDownload") |
|||
public void inventoryImportDownload(HttpServletRequest request, HttpServletResponse response) { |
|||
try { |
|||
|
|||
String path = "static/upload/inventoryImport.xlsx"; |
|||
|
|||
String fileName = "inventoryImport.xlsx"; |
|||
response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8")); |
|||
response.setContentType("content-type:octet-stream"); |
|||
/* .getClassLoader() 方法是在静态文件路径添加一个/ */ |
|||
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(path); |
|||
OutputStream outputStream = response.getOutputStream(); |
|||
try { |
|||
byte[] buffer = new byte[1024]; |
|||
int len; |
|||
assert inputStream != null; |
|||
while ((len = inputStream.read(buffer)) != -1) { /* 将流中内容写出去 .*/ |
|||
outputStream.write(buffer, 0, len); |
|||
} |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} finally { |
|||
assert inputStream != null; |
|||
inputStream.close(); |
|||
outputStream.close(); |
|||
} |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
|
|||
|
|||
@RequestMapping("/helpDocumentDownload") |
|||
public void helpDocumentDownload(HttpServletRequest request, HttpServletResponse response) { |
|||
try { |
|||
String path = "static/upload/helpDocumentForAdmin-pc.pdf"; |
|||
String userAgent = request.getHeader("user-agent"); |
|||
// 判断当前使用的设备为移动端还是pc端
|
|||
boolean b = DeviceUtil.checkAgentIsMobile(userAgent); |
|||
// 获取访问token
|
|||
String token = request.getHeader("user-token"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
Long maindeparment = userToken.getMaindeparment(); |
|||
if (b) { |
|||
// 如果是移动端
|
|||
if (PublicConfig.roleAdminorgList.contains(maindeparment)) { |
|||
path = "static/upload/helpDocumentForAdmin-mobile.pdf"; |
|||
} else { |
|||
path = "static/upload/helpDocumentForUser-mobile.pdf"; |
|||
|
|||
} |
|||
} else { |
|||
// 如果是pc端
|
|||
if (PublicConfig.roleAdminorgList.contains(maindeparment)) { |
|||
path = "static/upload/helpDocumentForAdmin-pc.pdf"; |
|||
} else { |
|||
path = "static/upload/helpDocumentForUser-pc.pdf"; |
|||
} |
|||
} |
|||
String fileName = "helpDocument.pdf"; |
|||
response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8")); |
|||
response.setContentType("content-type:octet-stream"); |
|||
/* .getClassLoader() 方法是在静态文件路径添加一个/ */ |
|||
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(path); |
|||
OutputStream outputStream = response.getOutputStream(); |
|||
try { |
|||
byte[] buffer = new byte[1024]; |
|||
int len; |
|||
assert inputStream != null; |
|||
while ((len = inputStream.read(buffer)) != -1) { /* 将流中内容写出去 .*/ |
|||
outputStream.write(buffer, 0, len); |
|||
} |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} finally { |
|||
assert inputStream != null; |
|||
inputStream.close(); |
|||
outputStream.close(); |
|||
} |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,157 @@ |
|||
package com.dreamchaser.depository_manage.controller; |
|||
|
|||
import com.dreamchaser.depository_manage.entity.UserByPort; |
|||
import com.dreamchaser.depository_manage.pojo.RestResponse; |
|||
import com.dreamchaser.depository_manage.security.pool.AuthenticationTokenPool; |
|||
import com.dreamchaser.depository_manage.service.ExcelService; |
|||
import com.dreamchaser.depository_manage.utils.CrudUtil; |
|||
import com.dreamchaser.depository_manage.utils.ResultVo; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 用于excel导入的控制器 |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("/excel") |
|||
public class ExcelController { |
|||
@Autowired |
|||
ExcelService excelService; |
|||
|
|||
/** |
|||
* 用于物料的导入 |
|||
* |
|||
* @param excel |
|||
* @return |
|||
*/ |
|||
@PostMapping("/importExcelByMaterial") |
|||
public ResultVo importExcelByMaterial(@RequestParam("file") MultipartFile excel, HttpServletRequest request) { |
|||
String token = request.getHeader("user-token"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
return excelService.importExcelMaterial(excel,userToken); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于物料类型的导入 |
|||
* |
|||
* @param excel |
|||
* @return |
|||
*/ |
|||
@PostMapping("/importExcelByMT") |
|||
public ResultVo importExcelByMT(@RequestParam("file") MultipartFile excel, HttpServletRequest request) { |
|||
String token = request.getHeader("user-token"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
return excelService.importExcelMaterialType(excel,userToken); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于库存信息的导入 |
|||
*/ |
|||
@PostMapping("/importInventory") |
|||
public ResultVo importInventory(@RequestParam("file") MultipartFile excel, HttpServletRequest request) { |
|||
String token = request.getHeader("user-token"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
return excelService.importExcelInventory(excel,userToken); |
|||
} |
|||
|
|||
/** |
|||
* 用于实际导入库存信息 |
|||
* @param map |
|||
*/ |
|||
@PostMapping("/realImportInventory") |
|||
public RestResponse realImportInventory(@RequestBody Map<String, String> map,HttpServletRequest request) { |
|||
String s = map.get("result"); |
|||
String token = request.getHeader("user-token"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
if ("yes".equals(s)) { |
|||
excelService.executeImportForInventory(userToken); |
|||
}else{ |
|||
excelService.clearImportFileData(userToken); |
|||
} |
|||
return CrudUtil.insertHandle(1,1); |
|||
} |
|||
|
|||
/** |
|||
* 用于覆盖之前导入的物料数据 |
|||
* @param map 覆盖的数据 |
|||
* @return |
|||
*/ |
|||
@PostMapping("/overwriteExcelByMaterial") |
|||
public RestResponse overwriteExcelByMaterial(@RequestBody Map<String,String> map,HttpServletRequest request){ |
|||
String s = map.get("result"); |
|||
String token = request.getHeader("user-token"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
if ("yes".equals(s)) { |
|||
excelService.executeOverwriteForMaterial(userToken); |
|||
}else{ |
|||
excelService.clearImportFileData(userToken); |
|||
} |
|||
return CrudUtil.updateHandle(1,1); |
|||
} |
|||
|
|||
|
|||
|
|||
/** |
|||
* 用于实际导入物料类型信息 |
|||
* @param map |
|||
*/ |
|||
@PostMapping("/realImportMaterialType") |
|||
public RestResponse realImportMaterialType(@RequestBody Map<String, String> map,HttpServletRequest request) { |
|||
String s = map.get("result"); |
|||
String token = request.getHeader("user-token"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
if ("yes".equals(s)) { |
|||
excelService.executeImportForMaterialType(userToken); |
|||
}else{ |
|||
excelService.clearImportFileData(userToken); |
|||
} |
|||
return CrudUtil.insertHandle(1,1); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于实际导入物料信息 |
|||
* @param map |
|||
*/ |
|||
@PostMapping("/realImportMaterial") |
|||
public RestResponse realImportMaterial(@RequestBody Map<String, String> map, HttpServletRequest request) { |
|||
String s = map.get("result"); |
|||
String token = request.getHeader("user-token"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
if ("yes".equals(s)) { |
|||
excelService.executeImportForMaterial(userToken); |
|||
}else{ |
|||
excelService.clearImportFileData(userToken); |
|||
} |
|||
return CrudUtil.insertHandle(1,1); |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,990 @@ |
|||
package com.dreamchaser.depository_manage.controller; |
|||
|
|||
import cn.hutool.core.lang.Snowflake; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.dreamchaser.depository_manage.entity.*; |
|||
import com.dreamchaser.depository_manage.exception.MyException; |
|||
import com.dreamchaser.depository_manage.pojo.GroupInfoP; |
|||
import com.dreamchaser.depository_manage.pojo.RestResponse; |
|||
import com.dreamchaser.depository_manage.pojo.RoleAndDepository; |
|||
import com.dreamchaser.depository_manage.pojo.StatusInfo; |
|||
import com.dreamchaser.depository_manage.security.pool.AuthenticationTokenPool; |
|||
import com.dreamchaser.depository_manage.security.pool.RedisPool; |
|||
import com.dreamchaser.depository_manage.security.pool.SendQyWxMessageThreadPool; |
|||
import com.dreamchaser.depository_manage.service.*; |
|||
import com.dreamchaser.depository_manage.service.impl.QyWxOperationService; |
|||
import com.dreamchaser.depository_manage.utils.*; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import java.io.IOException; |
|||
import java.util.*; |
|||
import java.util.concurrent.TimeUnit; |
|||
|
|||
@RestController |
|||
@RequestMapping("/group") |
|||
public class GroupController { |
|||
|
|||
@Autowired |
|||
GroupService groupService; |
|||
|
|||
@Autowired |
|||
DepositoryService depositoryService; |
|||
|
|||
@Autowired |
|||
MaterialService materialService; |
|||
|
|||
@Autowired |
|||
private QyWxOperationService qyWxOperationService; |
|||
|
|||
@Autowired |
|||
private RedisPool redisPool; |
|||
|
|||
@Autowired |
|||
private RoleService roleService; |
|||
|
|||
|
|||
@Autowired |
|||
private SplitUnitService splitUnitService; |
|||
|
|||
@Autowired |
|||
private UserService userService; |
|||
|
|||
|
|||
/** |
|||
* 用于添加一条组合记录 |
|||
* |
|||
* @param map 添加数据 |
|||
* @param request |
|||
* @return |
|||
*/ |
|||
@PostMapping("/addGroup") |
|||
public RestResponse addGroup(@RequestBody Map<String, Object> map, HttpServletRequest request) { |
|||
// 获取物料数量
|
|||
Integer len = ObjectFormatUtil.toInteger(map.get("len")); |
|||
// 获取添加成功的数量
|
|||
Integer integer = groupService.addGroup(map); |
|||
return CrudUtil.insertHandle(len, integer); |
|||
} |
|||
|
|||
@PostMapping("/findGroupByCodeForIn") |
|||
public RestResponse findGroupByCodeForIn(@RequestBody Map<String, Object> map, HttpServletRequest request) { |
|||
String code = map.get("code").toString(); |
|||
|
|||
// 获取组合编码
|
|||
Group groupByCode = groupService.findGroupByCode(code); |
|||
if (groupByCode != null) { |
|||
List<GroupInfo> groupByGid = groupService.findGroupInfoByGid(groupByCode.getId()); |
|||
return new RestResponse(groupByGid); |
|||
} else { |
|||
return new RestResponse(null, 666, new StatusInfo("失败", "暂无该组合,请确认是否正确")); |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于出库时查找对应编码的组合 |
|||
* |
|||
* @param map 查询条件 |
|||
* @param request |
|||
* @return |
|||
*/ |
|||
@PostMapping("/findGroupByCode") |
|||
public RestResponse findGroupByCode(@RequestBody Map<String, Object> map, HttpServletRequest request) { |
|||
String token = request.getHeader("user-token"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
|
|||
List<Long> depositoryIdList = roleService.findDepositoryIdForUserHas(userToken); |
|||
|
|||
String code = map.get("code").toString(); |
|||
|
|||
// 获取组合编码
|
|||
Group groupByCode = groupService.findGroupByCode(code); |
|||
|
|||
StringBuilder errMsg = new StringBuilder(); |
|||
|
|||
if (groupByCode != null) { |
|||
|
|||
|
|||
List<GroupInfo> groupByGid = groupService.findGroupInfoByGid(groupByCode.getId()); |
|||
|
|||
// 用于标识当前组合是否可以正常出库
|
|||
boolean flag = true; |
|||
// 定义符合要求的仓库id
|
|||
List<Long> satisfyDepositoryIdList = new ArrayList<>(); |
|||
for (GroupInfo groupInfo : groupByGid) { |
|||
|
|||
// 获取详细信息
|
|||
|
|||
Integer infoQuantity = groupInfo.getQuantity(); |
|||
// 获取该物料的库存
|
|||
Map<Long, Double> inventoryByGroupInfoAndDepository = materialService.findInventoryByGroupInfoAndDepository(groupInfo, depositoryIdList); |
|||
// 用于标志当前物料库存是否符合要求
|
|||
boolean flagForQuantity = false; |
|||
// 获取key 的迭代
|
|||
for (Long depositoryId : inventoryByGroupInfoAndDepository.keySet()) { |
|||
Double quantity = inventoryByGroupInfoAndDepository.get(depositoryId); |
|||
// 如果库存符合要求
|
|||
if (quantity >= infoQuantity) { |
|||
flagForQuantity = true; |
|||
if (!satisfyDepositoryIdList.contains(depositoryId)) { |
|||
satisfyDepositoryIdList.add(depositoryId); |
|||
} |
|||
} |
|||
} |
|||
if (!flagForQuantity) { |
|||
// 如果当前不符合
|
|||
flag = false; |
|||
errMsg.append(" ").append(groupInfo.getMname()).append(" "); |
|||
break; |
|||
} else { |
|||
List<Depository> depositoryByIds = depositoryService.findDepositoryByIds(satisfyDepositoryIdList); |
|||
groupInfo.setSatisfyDepositoryList(depositoryByIds); |
|||
} |
|||
|
|||
} |
|||
if (flag) { |
|||
return new RestResponse(groupByGid); |
|||
} else { |
|||
return new RestResponse(null, 666, new StatusInfo("不能出库", "当前组合中的 " + errMsg.toString() + "库存不足")); |
|||
} |
|||
} else { |
|||
return new RestResponse(null, 666, new StatusInfo("失败", "暂无该组合,请确认是否正确")); |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于给组合添加物料信息 |
|||
* |
|||
* @param map 添加物料信息 |
|||
* @param request |
|||
* @return |
|||
*/ |
|||
@PostMapping("/addMaterialForGroup") |
|||
public RestResponse addMaterialForGroup(@RequestBody Map<String, Object> map, HttpServletRequest request) { |
|||
if (map.containsKey("gid")) { |
|||
// 获取物料数量
|
|||
Integer len = ObjectFormatUtil.toInteger(map.get("len")); |
|||
|
|||
Integer integer = groupService.addMaterialForGroup(map); |
|||
return CrudUtil.insertHandle(len, integer); |
|||
} else { |
|||
throw new MyException("缺少必要参数"); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 根据条件获取所有组合 |
|||
* |
|||
* @param map 查询条件 |
|||
* @return |
|||
*/ |
|||
@GetMapping("/findAllGroup") |
|||
public RestResponse findAllGroup(@RequestParam Map<String, Object> map) { |
|||
if (map.containsKey("createTime")) { |
|||
String createTime = (String) map.get("createTime"); |
|||
Long timeStamp = DateUtil.DateTimeToTimeStamp(createTime); |
|||
map.put("createTime", timeStamp); |
|||
} |
|||
if (!map.containsKey("state")) { |
|||
map.put("state", 1); |
|||
} |
|||
List<GroupInfoP> groupPByCondition = groupService.findOnlyGroupByCondition(map); |
|||
return new RestResponse(groupPByCondition, groupService.findAllGroupOnlyCount(map), 200); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 根据组合名称获取组合 |
|||
* |
|||
* @param map 组合名称 |
|||
* @return |
|||
*/ |
|||
@PostMapping("/findGroupByGname") |
|||
public RestResponse findGroupByGname(@RequestBody Map<String, Object> map, HttpServletRequest request) { |
|||
String token = request.getHeader("user-token"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
if (map.containsKey("gname")) { |
|||
List<Group> groupOnlyByCondition = groupService.findGroupOnlyByCondition(map); |
|||
int size = groupOnlyByCondition.size(); |
|||
if (size > 1) { |
|||
// 如果当前名称的组合大于1个
|
|||
|
|||
return new RestResponse("", -1, 444); |
|||
} else if (size == 1) { |
|||
// 如果刚好只有一个
|
|||
// 获取当前组合的所有物料数据
|
|||
List<GroupInfo> groupByGid = groupService.findGroupByCondition(map); |
|||
List<Long> depositoryIdForUserHas = roleService.findDepositoryIdForUserHas(userToken); |
|||
List<Depository> depositoryByIds = depositoryService.findDepositoryByIds(depositoryIdForUserHas); |
|||
if (groupByGid != null && groupByGid.size() > 0) { |
|||
groupByGid.get(0).setSatisfyDepositoryList(depositoryByIds); |
|||
} else { |
|||
groupByGid = new ArrayList<>(); |
|||
} |
|||
return new RestResponse(groupByGid, groupByGid.size(), 200); |
|||
|
|||
} else { |
|||
// 如果没有
|
|||
return new RestResponse("", 0, 666); |
|||
} |
|||
} else { |
|||
throw new MyException("缺少必要参数"); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 查询组合详情 |
|||
* |
|||
* @param map |
|||
* @return |
|||
*/ |
|||
@GetMapping("/findGroupInfo") |
|||
public RestResponse findGroupInfo(@RequestParam Map<String, Object> map) { |
|||
if (map.containsKey("gid")) { |
|||
List<GroupInfo> groupByCondition = groupService.findGroupByCondition(map); |
|||
return new RestResponse(groupByCondition, groupService.findGroupCountByCondition(map), 200); |
|||
} else { |
|||
throw new MyException("缺失必要参数!"); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 修改组合中的物料数据 |
|||
* |
|||
* @param map |
|||
* @return |
|||
*/ |
|||
@PostMapping("/materialForGroupEdit") |
|||
public RestResponse materialForGroupEdit(@RequestBody Map<String, Object> map) { |
|||
if (map.containsKey("id")) { |
|||
Integer integer = groupService.updateMaterialForGroup(map); |
|||
return CrudUtil.updateHandle(1, integer); |
|||
} else { |
|||
throw new MyException("缺少必要参数!"); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 删除组合中的物料 |
|||
* |
|||
* @param map 删除条件 |
|||
* @return |
|||
*/ |
|||
@PostMapping("/delMaterialForGroup") |
|||
public RestResponse delMaterialForGroup(@RequestBody Map<String, Object> map) { |
|||
if (map.containsKey("id")) { |
|||
Long id = ObjectFormatUtil.toLong(map.get("id")); |
|||
Integer integer = groupService.delMaterialForGroupById(id); |
|||
return CrudUtil.deleteHandle(1, integer); |
|||
|
|||
} else if (map.containsKey("ids")) { |
|||
List<Long> ids = ObjectFormatUtil.objToList(map.get("ids"), Long.class); |
|||
Integer integer = groupService.delMaterialForGroupByIds(ids); |
|||
return CrudUtil.deleteHandle(ids.size(), integer); |
|||
} else { |
|||
throw new MyException("缺少必要参数"); |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于修改组合的状态 |
|||
* |
|||
* @param map 条件 |
|||
* @return |
|||
*/ |
|||
@PostMapping("/changeGroupState") |
|||
public RestResponse changeGroupState(@RequestBody Map<String, Object> map) { |
|||
if (map.containsKey("id")) { |
|||
Integer integer = groupService.updateGroupState(map); |
|||
return CrudUtil.updateHandle(1, integer); |
|||
} else { |
|||
throw new MyException("缺少必要参数"); |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于修改组合信息 |
|||
* |
|||
* @param map 修改条件 |
|||
* @return |
|||
*/ |
|||
@PostMapping("/editGroupInfo") |
|||
public RestResponse editGroupInfo(@RequestBody Map<String, Object> map) { |
|||
if (map.containsKey("id")) { |
|||
Integer integer = groupService.updateGroupInfo(map); |
|||
return CrudUtil.updateHandle(1, integer); |
|||
} else { |
|||
throw new MyException("缺少必要参数"); |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 删除组合(软删除) |
|||
* |
|||
* @param map 删除条件 |
|||
* @return |
|||
*/ |
|||
@PostMapping("/delGroup") |
|||
public RestResponse delGroup(@RequestBody Map<String, Object> map) { |
|||
if (map.containsKey("id")) { |
|||
map.put("state", 3); |
|||
Integer integer = groupService.updateGroupState(map); |
|||
return CrudUtil.updateHandle(1, integer); |
|||
} else if (map.containsKey("ids")) { |
|||
List<Long> ids = ObjectFormatUtil.objToList(map.get("ids"), Long.class); |
|||
Integer integer = 0; |
|||
for (Long id : ids) { |
|||
map.put("id", id); |
|||
map.put("state", 3); |
|||
integer += groupService.updateGroupState(map); |
|||
} |
|||
return CrudUtil.updateHandle(ids.size(), integer); |
|||
} else { |
|||
throw new MyException("缺少必要参数"); |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 删除组合及其明细(硬删除) |
|||
* |
|||
* @param map 删除条件 |
|||
* @return |
|||
*/ |
|||
@PostMapping("/realDelGroup") |
|||
public RestResponse realDelGroup(@RequestBody Map<String, Object> map) { |
|||
if (map.containsKey("id")) { |
|||
Long id = ObjectFormatUtil.toLong(map.get("id")); |
|||
Integer integer = groupService.delGroupById(id); |
|||
return CrudUtil.deleteHandle(1, integer); |
|||
} else { |
|||
throw new MyException("缺少必要参数"); |
|||
} |
|||
} |
|||
|
|||
@PostMapping("/findGroupInfoByGid") |
|||
public RestResponse findGroupInfoByGid(@RequestBody Map<String, Object> map, HttpServletRequest request) { |
|||
|
|||
|
|||
String token = request.getHeader("user-token"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
|
|||
List<Long> depositoryIdList = new ArrayList<>(); |
|||
|
|||
depositoryIdList = roleService.findDepositoryIdForUserHas(userToken); |
|||
|
|||
// 获取当前组合的所有物料数据
|
|||
List<GroupInfo> groupByGid = groupService.findGroupByCondition(map); |
|||
|
|||
// 定义错误信息
|
|||
StringBuilder errMsg = new StringBuilder(); |
|||
|
|||
String type = (String) map.get("type"); |
|||
// 用于标识当前组合是否可以正常出库
|
|||
boolean flag = true; |
|||
|
|||
if (!"in".equals(type)) { |
|||
// 定义符合要求的仓库id
|
|||
List<Long> satisfyDepositoryIdList = new ArrayList<>(); |
|||
for (GroupInfo groupInfo : groupByGid) { |
|||
|
|||
// 获取详细信息
|
|||
// 获取该物料的库存
|
|||
Integer infoQuantity = groupInfo.getQuantity(); |
|||
|
|||
// 用于标志当前物料库存是否符合要求
|
|||
boolean flagForQuantity = false; |
|||
// 获取该物料在各仓库的库存
|
|||
Map<Long, Double> inventoryByMidAndDepository = materialService.findInventoryByGroupInfoAndDepository(groupInfo, depositoryIdList); |
|||
// 获取key的迭代器
|
|||
for (Long depositoryId : inventoryByMidAndDepository.keySet()) { |
|||
Double value = inventoryByMidAndDepository.get(depositoryId); |
|||
if (value >= infoQuantity) { |
|||
flagForQuantity = true; |
|||
satisfyDepositoryIdList.add(depositoryId); |
|||
} |
|||
} |
|||
|
|||
|
|||
if (!flagForQuantity) { |
|||
// 如果当前不符合
|
|||
flag = false; |
|||
errMsg.append(" ").append(groupInfo.getMname()).append(" "); |
|||
break; |
|||
} else { |
|||
List<Depository> depositoryByIds = depositoryService.findDepositoryByIds(satisfyDepositoryIdList); |
|||
groupInfo.setSatisfyDepositoryList(depositoryByIds); |
|||
} |
|||
|
|||
} |
|||
} |
|||
if (flag) { |
|||
|
|||
return new RestResponse(groupByGid); |
|||
} else { |
|||
return new RestResponse(null, 666, new StatusInfo("不能出库", "当前组合中的" + errMsg + "在仓库中库存不足")); |
|||
} |
|||
} |
|||
|
|||
|
|||
@PostMapping("/treeMenus") |
|||
public RestResponse treeMenus(@RequestBody Map<String, Object> map) { |
|||
String gname = ""; |
|||
if (map.containsKey("gname")) { |
|||
gname = (String) map.get("gname"); |
|||
} |
|||
List<Object> list = groupService.InitTreeMenus(gname); |
|||
return new RestResponse(list); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 将选中的物料暂存到redis中 |
|||
* |
|||
* @param map 暂存的数据 |
|||
* @param request |
|||
* @return |
|||
*/ |
|||
@PostMapping("/addApplicationToRedis") |
|||
public RestResponse addApplicationToRedis(@RequestBody Map<String, Object> map, HttpServletRequest request) { |
|||
String token = request.getHeader("user-token"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
// 获取暂存的数据
|
|||
List<Long> gids = ObjectFormatUtil.objToList(map.get("gids"), Long.class); |
|||
// 获取当前已经存在的数据
|
|||
List<String> range = redisPool.getRedisTemplateByDb(15).opsForList().range("wms_gids" + userToken.getId(), 0, -1); |
|||
for (Long gid : gids) { |
|||
if (range != null) { |
|||
if (range.contains(gid.toString())) { |
|||
continue; |
|||
} |
|||
} |
|||
redisPool.getRedisTemplateByDb(15).opsForList().leftPush("wms_gids" + userToken.getId(), gid.toString()); |
|||
|
|||
} |
|||
// 设置过期时间为1天
|
|||
redisPool.getRedisTemplateByDb(15).expire("wms_gids" + userToken.getId(), 24 * 60 * 60, TimeUnit.SECONDS); |
|||
return CrudUtil.insertHandle(1, 1); |
|||
} |
|||
|
|||
/** |
|||
* 用于查询当前多选选中的组合 |
|||
* |
|||
* @param map 查询条件 |
|||
* @param request |
|||
* @return |
|||
*/ |
|||
@GetMapping("/applicant_multi_create") |
|||
public RestResponse applicant_multi_create(@RequestParam Map<String, Object> map, HttpServletRequest request) { |
|||
Integer page = ObjectFormatUtil.toInteger(map.get("page")); |
|||
Integer pagesize = ObjectFormatUtil.toInteger(map.get("size")); |
|||
int start = (page - 1) * pagesize; |
|||
Integer end = page * 10; |
|||
String token = request.getHeader("user-token"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
Long size = redisPool.getRedisTemplateByDb(15).boundListOps("wms_gids" + userToken.getId()).size(); |
|||
if (size != null) { |
|||
if (end > size) { |
|||
end = ObjectFormatUtil.toInteger(size); |
|||
} |
|||
}else{ |
|||
size = 0L; |
|||
} |
|||
List<GroupInfoP> list = new ArrayList<>(); |
|||
Map<String, Object> paramForGroupOnly = new HashMap<>(); |
|||
for (int i = start; i < end; i++) { |
|||
// 获取组合编号
|
|||
Integer gid = ObjectFormatUtil.toInteger(redisPool.getRedisTemplateByDb(15).opsForList().index("wms_gids" + userToken.getId(), i)); |
|||
paramForGroupOnly.put("gid", gid); |
|||
List<GroupInfoP> groupPByCondition = groupService.findOnlyGroupByCondition(paramForGroupOnly); |
|||
for (GroupInfoP groupInfoP : groupPByCondition) { |
|||
groupInfoP.setQuantity(1); |
|||
list.add(groupInfoP); |
|||
} |
|||
|
|||
} |
|||
return new RestResponse(list, ObjectFormatUtil.toInteger(size), 200); |
|||
} |
|||
|
|||
/** |
|||
* 将选中的组合从redis中删除 |
|||
* |
|||
* @param map 待删除的数据 |
|||
* @param request |
|||
* @return |
|||
*/ |
|||
@PostMapping("/deleteApplicationToRedis") |
|||
public RestResponse deleteApplicationToRedis(@RequestBody Map<String, Object> map, HttpServletRequest request) { |
|||
String token = request.getHeader("user-token"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
List<Long> gids = ObjectFormatUtil.objToList(map.get("gids"),Long.class); |
|||
for (Long gid : gids) { |
|||
redisPool.getRedisTemplateByDb(15).opsForList().remove("wms_gids" + userToken.getId(), 1, gid.toString()); |
|||
} |
|||
return CrudUtil.insertHandle(1, 1); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于构造组合入库单 |
|||
* |
|||
* @param map 入库数据 |
|||
* @param request |
|||
* @return |
|||
*/ |
|||
@PostMapping("/applicationInForGroup") |
|||
public RestResponse applicationInForGroup(@RequestBody Map<String, Object> map, HttpServletRequest request) { |
|||
String token = request.getHeader("user-token"); |
|||
String userKey = request.getHeader("user-key"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
userKey = (String) request.getSession().getAttribute("userKey"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
String header = request.getHeader("user-agent"); |
|||
String crypt = Md5.crypt(header); |
|||
// 获取当前提交数
|
|||
List<String> params = ObjectFormatUtil.objToList(map.get("params"),String.class); |
|||
// 执行结果
|
|||
Integer integer = 0; |
|||
// 实际结果
|
|||
int result = 0; |
|||
Long gid = ObjectFormatUtil.toLong(map.get("gid")); |
|||
List<GroupInfo> groupInfoByGid = groupService.findGroupInfoByGid(gid); |
|||
if (groupInfoByGid != null) { |
|||
result += groupInfoByGid.size(); |
|||
} |
|||
for (String param : params) { |
|||
gid = ObjectFormatUtil.toLong(map.get("gid" + param)); |
|||
groupInfoByGid = groupService.findGroupInfoByGid(gid); |
|||
if (groupInfoByGid != null) { |
|||
result += groupInfoByGid.size(); |
|||
} |
|||
} |
|||
try { |
|||
integer += groupService.insertApplicationInRecord(map, userToken, crypt, userKey, token); // 插入主订单
|
|||
} catch (Exception e) { |
|||
return new RestResponse("", 666, new StatusInfo("出库失败", e.getMessage())); |
|||
} |
|||
return CrudUtil.updateHandle(result, integer); |
|||
} |
|||
|
|||
/** |
|||
* 入库审核 |
|||
* |
|||
* @param map |
|||
* @param request |
|||
* @return |
|||
*/ |
|||
@PutMapping("/reviewIn") |
|||
public RestResponse reviewIn(@RequestBody Map<String, Object> map, HttpServletRequest request) { |
|||
String token = request.getHeader("user-token"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
String header = request.getHeader("user-agent"); |
|||
String crypt = Md5.crypt(header); |
|||
Integer review = groupService.reviewIn(map, userToken.getId(), userToken, crypt); |
|||
if (review != -1) { |
|||
return CrudUtil.insertHandle(review, 1); |
|||
} else { |
|||
return new RestResponse("", 666, new StatusInfo("出库失败", "当前存储位库存不足,请重新选择")); |
|||
} |
|||
} |
|||
|
|||
@PostMapping("/findGroupById") |
|||
public RestResponse findGroupById(@RequestBody Map<String, String> map) { |
|||
if (map.containsKey("id")) { |
|||
return new RestResponse(groupService.findGroupOnlyById(ObjectFormatUtil.toLong(map.get("id")))); |
|||
} else { |
|||
throw new MyException("缺少必要参数"); |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于获取当前物料在组合中的详细信息 |
|||
* |
|||
* @param map |
|||
* @return |
|||
*/ |
|||
@PostMapping("/materialInfoForGroup") |
|||
public RestResponse materialInfoForGroup(@RequestBody Map<String, String> map) { |
|||
if (map.containsKey("mid") && map.containsKey("gid")) { |
|||
Long mid = ObjectFormatUtil.toLong(map.get("mid")); |
|||
Long gid = ObjectFormatUtil.toLong(map.get("gid")); |
|||
GroupInfo groupInfoByMidAndGid = groupService.findGroupInfoByMidAndGid(mid, gid); |
|||
Map<String, Object> result = new HashMap<>(); |
|||
if (groupInfoByMidAndGid != null) { |
|||
List<SplitInfo> splitInfoByMid = splitUnitService.findSplitInfoByMid(groupInfoByMidAndGid.getMid()); |
|||
result.put("groupInfo", groupInfoByMidAndGid); |
|||
result.put("splitList", splitInfoByMid); |
|||
} |
|||
return new RestResponse(result); |
|||
} else { |
|||
throw new MyException("缺少必要参数"); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 用于构造组合出库单 |
|||
* |
|||
* @param map 出库数据 |
|||
* @param request |
|||
* @return |
|||
*/ |
|||
@PostMapping("/applicationOutForGroup") |
|||
public RestResponse applicationOutForGroup(@RequestBody Map<String, Object> map, HttpServletRequest request) { |
|||
String token = request.getHeader("user-token"); |
|||
String userkey = request.getHeader("user-key"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
userkey = (String) request.getSession().getAttribute("userKey"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
String header = request.getHeader("user-agent"); |
|||
String crypt = Md5.crypt(header); |
|||
map.put("applicantId", userToken.getId()); |
|||
|
|||
// 获取当前部门负责人
|
|||
List<UserByPort> departmentHeadByUsers = userService.getDepartmentHeaderByIdForNoPack(userToken.getMaindeparment()); |
|||
// 部门负责人id
|
|||
StringBuilder departmentHeadId = new StringBuilder(); |
|||
// 部门负责人企业微信user
|
|||
for (UserByPort departmentHeadByUser : departmentHeadByUsers) { |
|||
departmentHeadId.append(departmentHeadByUser.getId()).append(","); |
|||
} |
|||
// departmentHeadId = new StringBuilder("78").append(",");
|
|||
map.put("departmenthead", departmentHeadId.toString()); |
|||
// 获取当前提交数
|
|||
List<String> params = ObjectFormatUtil.objToList(map.get("params"),String.class); |
|||
// 执行结果
|
|||
Integer integer = 0; |
|||
// 实际结果
|
|||
int result = 0; |
|||
Long gid = ObjectFormatUtil.toLong(map.get("gid")); |
|||
List<GroupInfo> groupInfoByGid = groupService.findGroupInfoByGid(gid); |
|||
if (groupInfoByGid != null) { |
|||
result += groupInfoByGid.size(); |
|||
} |
|||
for (String param : params) { |
|||
gid = ObjectFormatUtil.toLong(map.get("gid" + param)); |
|||
groupInfoByGid = groupService.findGroupInfoByGid(gid); |
|||
if (groupInfoByGid != null) { |
|||
result += groupInfoByGid.size(); |
|||
} |
|||
} |
|||
if (map.containsKey("constructionUnitId")) { |
|||
String constructionUnitId = map.get("constructionUnitId").toString(); |
|||
if ("".equals(constructionUnitId)) { |
|||
map.remove("constructionUnitId"); |
|||
} |
|||
} |
|||
if (map.containsKey("adminorgId")) { |
|||
String adminorgId = map.get("adminorgId").toString(); |
|||
if ("".equals(adminorgId)) { |
|||
map.put("adminorgId", userToken.getMaindeparment()); |
|||
} |
|||
} else { |
|||
map.put("adminorgId", userToken.getMaindeparment()); |
|||
} |
|||
try { |
|||
integer += groupService.insertApplicationOutRecord(map, userToken, userkey, token); // 插入主订单
|
|||
} catch (Exception e) { |
|||
return new RestResponse("", 666, new StatusInfo("出库失败", e.getMessage())); |
|||
} |
|||
Object id = map.get("id"); // 获取主订单编号
|
|||
// 开启一个线程开启审批
|
|||
String finalUserkey = userkey; |
|||
String finalToken = token; |
|||
SendQyWxMessageThreadPool.execute(() -> { |
|||
JSONObject jsonObject = qyWxOperationService.sendOutApprovalTemplate(crypt, userToken, ObjectFormatUtil.toLong(id), finalUserkey, finalToken); |
|||
String sp_no = jsonObject.getString("sp_no"); |
|||
Map<String, Object> QyWxApprovalMap = new HashMap<>(); |
|||
QyWxApprovalMap.put("sp_no", sp_no); |
|||
QyWxApprovalMap.put("mainId", id.toString()); |
|||
QyWxApprovalMap.put("otherDepartmentIdList", jsonObject.getString("otherDepartmentIdList")); |
|||
redisPool.getRedisTemplateByDb(14).opsForHash().putAll("wms_QyWxMessage_" + sp_no, QyWxApprovalMap); |
|||
// 设置过期为7天
|
|||
redisPool.getRedisTemplateByDb(14).expire("wms_QyWxMessage_" + sp_no, 7, TimeUnit.DAYS); |
|||
}); |
|||
|
|||
if (integer != 0 && params.size() < 1) { |
|||
return CrudUtil.insertHandle(integer, result); |
|||
} else if (integer != 0 && params.size() >= 1) { |
|||
return CrudUtil.insertHandle(integer, result); |
|||
} else { |
|||
return new RestResponse("", 666, new StatusInfo("出库失败", "请联系管理员进行操作")); |
|||
} |
|||
|
|||
} |
|||
|
|||
// 构造组合二维码
|
|||
@PostMapping("/createQrCode") |
|||
public RestResponse createQrCode(@RequestBody Map<String, Object> map) { |
|||
// 通过雪花算法计算随机数
|
|||
Snowflake snowflake = new Snowflake(10, 10, true); |
|||
String qrCode = snowflake.nextIdStr(); |
|||
|
|||
Long gid = ObjectFormatUtil.toLong(map.get("gid")); |
|||
|
|||
String qrCodeByMcode = groupService.findQrCodeByGid(gid); |
|||
|
|||
if (qrCodeByMcode == null) { |
|||
Map<String, Object> param = new HashMap<>(); |
|||
param.put("gid", gid); |
|||
param.put("code", qrCode); |
|||
groupService.addQrCodeByGroup(param); |
|||
} else { |
|||
qrCode = qrCodeByMcode; |
|||
} |
|||
try { |
|||
// 二维码保存信息
|
|||
return RestResponse.CreateQrCode(qrCode); |
|||
} catch (IOException e) { |
|||
return new RestResponse("err: " + e.getMessage(), 678, new StatusInfo("失败", "请联系开发人员")); |
|||
} |
|||
|
|||
} |
|||
|
|||
/** |
|||
* 用于判断当前组合的数量是否合法 |
|||
* |
|||
* @param map 组合相关信息 |
|||
* @param request |
|||
* @return |
|||
*/ |
|||
@PostMapping("/groupQuantityIsTrue") |
|||
public RestResponse groupQuantityIsTrue(@RequestBody Map<String, Object> map, HttpServletRequest request) { |
|||
if (map.containsKey("gid")) { |
|||
String token = request.getHeader("user-token"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
|
|||
|
|||
// 获取组合id
|
|||
Long gid = ObjectFormatUtil.toLong(map.get("gid")); |
|||
// 获取组合数量
|
|||
Integer quantity = ObjectFormatUtil.toInteger(map.get("quantity")); |
|||
List<Long> depositoryIdList = new ArrayList<>(); |
|||
if (map.containsKey("depositoryId")) { |
|||
// 获取选择的仓库
|
|||
Long depositoryId = ObjectFormatUtil.toLong(map.get("depositoryId")); |
|||
depositoryIdList.add(depositoryId); |
|||
} else { |
|||
depositoryIdList = roleService.findDepositoryIdForUserHas(userToken); |
|||
} |
|||
|
|||
Map<String, String> trueForGroup = isTrueForGroup(gid, quantity, depositoryIdList); |
|||
Boolean flag = Boolean.valueOf(trueForGroup.get("flag")); |
|||
|
|||
String mname = trueForGroup.get("mname"); |
|||
return new RestResponse(flag, 200, new StatusInfo(mname, mname)); |
|||
} else { |
|||
throw new MyException("缺少必要参数"); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 用于构造组合出库订单 |
|||
* |
|||
* @param map 出库数据 |
|||
* @param request |
|||
* @return |
|||
*/ |
|||
@PostMapping("/createMultiApplication") |
|||
public RestResponse createMultiApplication(@RequestBody Map<String, Object> map, HttpServletRequest request) { |
|||
String token = request.getHeader("user-token"); |
|||
String userkey = request.getHeader("user-key"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
userkey = (String) request.getSession().getAttribute("userKey"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
String header = request.getHeader("user-agent"); |
|||
String crypt = Md5.crypt(header); |
|||
map.put("applicantId", userToken.getId()); |
|||
// 获取当前部门负责人
|
|||
List<UserByPort> departmentHeadByUsers = userService.getDepartmentHeaderByIdForNoPack(userToken.getMaindeparment()); |
|||
// 部门负责人id
|
|||
StringBuilder departmentHeadId = new StringBuilder(); |
|||
// 部门负责人企业微信user
|
|||
for (UserByPort departmentHeadByUser : departmentHeadByUsers) { |
|||
departmentHeadId.append(departmentHeadByUser.getId()).append(","); |
|||
} |
|||
// departmentHeadId = new StringBuilder("78").append(",");
|
|||
map.put("departmenthead", departmentHeadId.toString()); |
|||
|
|||
// 获取当前部门所拥有的仓库
|
|||
List<Depository> depositoryByAdminorg = depositoryService.findDepositoryByAdminorg(userToken.getMaindeparment().toString()); |
|||
// 查询当前用户管理的仓库
|
|||
List<RoleAndDepository> depositoryAndRole = roleService.findDepositoryAndRole(userToken.getId()); |
|||
depositoryAndRole.addAll(roleService.findDepositoryAndRole(userToken.getPosition())); |
|||
|
|||
List<Long> depositoryIdList = new ArrayList<>(); |
|||
for (Depository depository : depositoryByAdminorg |
|||
) { |
|||
depositoryIdList.add(depository.getId()); |
|||
} |
|||
for (RoleAndDepository rad : depositoryAndRole |
|||
) { |
|||
if (!depositoryIdList.contains(rad.getDepositoryId())) { |
|||
depositoryIdList.add(rad.getDepositoryId()); |
|||
} |
|||
} |
|||
|
|||
|
|||
// 执行结果
|
|||
Integer integer = 0; |
|||
// 实际结果
|
|||
int result = 0; |
|||
|
|||
// 获取当前出库类型
|
|||
String type = (String) map.get("type"); |
|||
if ("one".equals(type)) { |
|||
Long gid = ObjectFormatUtil.toLong(map.get("id")); |
|||
Integer quantity = ObjectFormatUtil.toInteger(map.get("quantity")); |
|||
Map<String, String> trueForGroup = isTrueForGroup(gid, quantity, depositoryIdList); |
|||
boolean flag = Boolean.parseBoolean(trueForGroup.get("flag")); |
|||
if (!flag) { |
|||
return new RestResponse("", 666, new StatusInfo("仓库中" + trueForGroup.get("mname") + "库存不足", "仓库中" + trueForGroup.get("mname") + "库存不足")); |
|||
} |
|||
map.put("gid", gid); |
|||
List<GroupInfo> groupInfoByGid = groupService.findGroupInfoByGid(gid); |
|||
if (groupInfoByGid != null) { |
|||
result += groupInfoByGid.size(); |
|||
} |
|||
} else { |
|||
// 用于同步出库算法
|
|||
int num = 0; |
|||
List<String> params = new ArrayList<>(); |
|||
// 获取当前提交数
|
|||
List<Long> gids = ObjectFormatUtil.objToList(map.get("gids"),Long.class); |
|||
List<Integer> quantitys = ObjectFormatUtil.objToList(map.get("quantitys"),Integer.class); |
|||
for (int i = 0; i < gids.size(); i++) { |
|||
|
|||
Long temp = gids.get(i); |
|||
Integer quantity = quantitys.get(i); |
|||
|
|||
Map<String, String> trueForGroup = isTrueForGroup(temp, quantity, depositoryIdList); |
|||
boolean flag = Boolean.parseBoolean(trueForGroup.get("flag")); |
|||
if (!flag) { |
|||
return new RestResponse("", 666, new StatusInfo("仓库中" + trueForGroup.get("mname") + "库存不足", "仓库中" + trueForGroup.get("mname") + "库存不足")); |
|||
} |
|||
List<GroupInfo> groupInfoByGid = groupService.findGroupInfoByGid(temp); |
|||
if (groupInfoByGid != null) { |
|||
result += groupInfoByGid.size(); |
|||
} |
|||
if (num == 0) { |
|||
map.put("gid", temp); |
|||
map.put("quantity", quantity); |
|||
num++; |
|||
} else { |
|||
map.put("gid" + num, temp); |
|||
map.put("quantity" + num, quantity); |
|||
params.add(String.valueOf((num++))); |
|||
} |
|||
} |
|||
map.put("params", params); |
|||
} |
|||
if (map.containsKey("constructionUnitId")) { |
|||
String constructionUnitId = map.get("constructionUnitId").toString(); |
|||
if ("".equals(constructionUnitId)) { |
|||
map.remove("constructionUnitId"); |
|||
} |
|||
} |
|||
if (map.containsKey("adminorgId")) { |
|||
String adminorgId = map.get("adminorgId").toString(); |
|||
if ("".equals(adminorgId)) { |
|||
map.put("adminorgId", userToken.getMaindeparment()); |
|||
} |
|||
} else { |
|||
map.put("adminorgId", userToken.getMaindeparment()); |
|||
} |
|||
try { |
|||
integer += groupService.insertApplicationOutRecord(map, userToken, userkey, token); // 插入主订单
|
|||
} catch (Exception e) { |
|||
return new RestResponse("", 666, new StatusInfo("出库失败", e.getMessage())); |
|||
} |
|||
Object id = map.get("id"); // 获取主订单编号
|
|||
// 开启一个线程开启审批
|
|||
String finalUserkey = userkey; |
|||
String finalToken = token; |
|||
SendQyWxMessageThreadPool.execute(() -> { |
|||
JSONObject jsonObject = qyWxOperationService.sendOutApprovalTemplate(crypt, userToken, ObjectFormatUtil.toLong(id), finalUserkey, finalToken); |
|||
String sp_no = jsonObject.getString("sp_no"); |
|||
Map<String, Object> QyWxApprovalMap = new HashMap<>(); |
|||
QyWxApprovalMap.put("sp_no", sp_no); |
|||
QyWxApprovalMap.put("mainId", id.toString()); |
|||
QyWxApprovalMap.put("otherDepartmentIdList", jsonObject.getString("otherDepartmentIdList")); |
|||
redisPool.getRedisTemplateByDb(14).opsForHash().putAll("wms_QyWxMessage_" + sp_no, QyWxApprovalMap); |
|||
// 设置过期为7天
|
|||
redisPool.getRedisTemplateByDb(14).expire("wms_QyWxMessage_" + sp_no, 7, TimeUnit.DAYS); |
|||
}); |
|||
return CrudUtil.insertHandle(integer, result); |
|||
|
|||
} |
|||
|
|||
|
|||
Map<String, String> isTrueForGroup(Long gid, Integer quantity, List<Long> depositoryIdList) { |
|||
List<GroupInfo> groupInfoByGid = groupService.findGroupInfoByGid(gid); |
|||
boolean flag = true; |
|||
String mname = ""; |
|||
for (GroupInfo groupInfo : groupInfoByGid) { |
|||
// 获取具体信息
|
|||
|
|||
// 获取本次要出库的实际的数量
|
|||
Integer totalQuantity = groupInfo.getQuantity() * quantity; |
|||
// 用于标志是否可以满足库存要求
|
|||
boolean flagForInventory = false; |
|||
|
|||
// 获取该物料在各仓库的库存
|
|||
Map<Long, Double> inventoryByMidAndDepository = materialService.findInventoryByGroupInfoAndDepository(groupInfo, depositoryIdList); |
|||
// 获取key的迭代器
|
|||
for (Long depositoryId : inventoryByMidAndDepository.keySet()) { |
|||
Double value = inventoryByMidAndDepository.get(depositoryId); |
|||
if (value >= totalQuantity) { |
|||
flagForInventory = true; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
if (!flagForInventory) { |
|||
// 如果概述了不合法
|
|||
flag = false; |
|||
} |
|||
mname = groupInfo.getMname(); |
|||
} |
|||
Map<String, String> result = new HashMap<>(); |
|||
result.put("flag", Boolean.toString(flag)); |
|||
result.put("mname", mname); |
|||
return result; |
|||
} |
|||
} |
|||
@ -0,0 +1,115 @@ |
|||
package com.dreamchaser.depository_manage.controller; |
|||
|
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.dreamchaser.depository_manage.config.PublicConfig; |
|||
import com.dreamchaser.depository_manage.entity.UserByPort; |
|||
import com.dreamchaser.depository_manage.security.pool.AuthenticationTokenPool; |
|||
import com.dreamchaser.depository_manage.security.pool.RedisPool; |
|||
import com.dreamchaser.depository_manage.service.UserService; |
|||
import com.dreamchaser.depository_manage.utils.EncryptionAlgorithmUtil; |
|||
import com.dreamchaser.depository_manage.utils.HttpUtils; |
|||
import lombok.extern.java.Log; |
|||
import lombok.extern.log4j.Log4j; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.http.protocol.HTTP; |
|||
import org.apache.ibatis.annotations.Param; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Controller; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RequestParam; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
import org.springframework.web.servlet.ModelAndView; |
|||
import javax.servlet.http.HttpServletRequest; |
|||
import javax.servlet.http.HttpServletResponse; |
|||
import java.io.IOException; |
|||
import java.time.Instant; |
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
|
|||
/** |
|||
* 用于智慧化工平台的一键登录 |
|||
*/ |
|||
@Slf4j |
|||
@RestController |
|||
public class IdentityVerifyController { |
|||
|
|||
|
|||
@Autowired |
|||
private RedisPool redisPool; |
|||
|
|||
@Autowired |
|||
private UserService userService; |
|||
|
|||
/** |
|||
* 用于验证用户身份 |
|||
*/ |
|||
@GetMapping("/identityVerify") |
|||
public ModelAndView identityVerify(@RequestParam Map<String,String> map, HttpServletRequest request, HttpServletResponse response){ |
|||
|
|||
ModelAndView mv = new ModelAndView(); |
|||
mv.addObject("userWxId", ""); |
|||
mv.setViewName("pages/user/login"); |
|||
|
|||
String url = PublicConfig.external_url_extranet+"/signcode/signcode"; |
|||
|
|||
String userkey = map.get("userkey"); |
|||
String usertoken = map.get("usertoken"); |
|||
String code = map.get("code"); |
|||
EncryptionAlgorithmUtil encryptionAlgorithmUtil = new EncryptionAlgorithmUtil(code); |
|||
// 获取加密后的字符串
|
|||
String algorithm = encryptionAlgorithmUtil.Algorithm(); |
|||
Map<String,String> paramForPost = new HashMap<>(); |
|||
paramForPost.put("code",algorithm); |
|||
String jsonString = JSONObject.toJSONString(paramForPost); |
|||
JSONObject paramObject = JSONObject.parseObject(jsonString); |
|||
try { |
|||
String send = HttpUtils.send(url, paramObject, HTTP.UTF_8, userkey, usertoken); |
|||
JSONObject resultObj = JSONObject.parseObject(send); |
|||
int resultCode = resultObj.getInteger("code"); |
|||
if(resultCode == 0){ |
|||
// 如果验证成功
|
|||
String redisKey = PublicConfig.LoginRedisPrefix + userkey; |
|||
Object usernumber = redisPool.getRedisTemplateByDb(5).opsForHash().get(redisKey, "usernumber"); |
|||
if(usernumber != null){ |
|||
UserByPort userByNumber = userService.findUserByNumber(String.valueOf(usernumber)); |
|||
|
|||
// 设置放入时间
|
|||
userByNumber.setInstant(Instant.now()); |
|||
// 将登录用户存储到池中保存
|
|||
AuthenticationTokenPool.addUserToken(usertoken,userByNumber); |
|||
|
|||
// 将key与token设置到session中
|
|||
request.getSession().setAttribute("userKey", userkey); |
|||
request.getSession().setAttribute("userToken", usertoken); |
|||
request.getSession().setMaxInactiveInterval(3 * 60 * 60); |
|||
|
|||
|
|||
try { |
|||
response.sendRedirect("http://localhost:11111"); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
}else{ |
|||
JSONObject captcha = PublicConfig.Captcha(request); |
|||
String picPath = (String) captcha.get("picPath"); |
|||
String captchaid = (String) captcha.get("captchaid"); |
|||
mv.addObject("picPath", picPath); |
|||
mv.addObject("captchaid", captchaid); |
|||
} |
|||
}else{ |
|||
// 如果验证失败
|
|||
JSONObject captcha = PublicConfig.Captcha(request); |
|||
String picPath = (String) captcha.get("picPath"); |
|||
String captchaid = (String) captcha.get("captchaid"); |
|||
mv.addObject("picPath", picPath); |
|||
mv.addObject("captchaid", captchaid); |
|||
} |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
return mv; |
|||
} |
|||
|
|||
} |
|||
File diff suppressed because it is too large
@ -0,0 +1,363 @@ |
|||
package com.dreamchaser.depository_manage.controller; |
|||
|
|||
import com.dreamchaser.depository_manage.entity.MaterialType; |
|||
import com.dreamchaser.depository_manage.exception.MyException; |
|||
import com.dreamchaser.depository_manage.pojo.MaterialP; |
|||
import com.dreamchaser.depository_manage.pojo.RestResponse; |
|||
import com.dreamchaser.depository_manage.security.pool.HandlesOtherFunctionalThreadPool; |
|||
import com.dreamchaser.depository_manage.service.MaterialService; |
|||
import com.dreamchaser.depository_manage.service.MaterialTypeService; |
|||
import com.dreamchaser.depository_manage.utils.CrudUtil; |
|||
import com.dreamchaser.depository_manage.utils.ObjectFormatUtil; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
@RestController |
|||
@RequestMapping("/materialType") |
|||
public class MaterialTypeController { |
|||
@Autowired |
|||
MaterialTypeService materialTypeService; |
|||
|
|||
@Autowired |
|||
MaterialService materialService; |
|||
|
|||
/** |
|||
* 插入一条新物料类型 |
|||
* @param map |
|||
* @return |
|||
*/ |
|||
@PostMapping("/materialType_add") |
|||
public RestResponse insertMaterialType(@RequestBody Map<String,Object> map){ |
|||
Integer integer = materialTypeService.insertMaterialType(map); |
|||
// 更新树结构
|
|||
HandlesOtherFunctionalThreadPool.execute(() -> { |
|||
try { |
|||
Thread.sleep(1000); |
|||
} catch (InterruptedException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
materialService.RefreshInitTreeMenus(); |
|||
}); |
|||
return CrudUtil.insertHandle(integer,1); |
|||
} |
|||
|
|||
/** |
|||
* 根据条件查询物料类型 |
|||
* @param map |
|||
* @return |
|||
*/ |
|||
@GetMapping("/materialTypeRecord") |
|||
public RestResponse findmaterialTypeRecordByCondition(@RequestParam Map<String,Object> map){ |
|||
List<MaterialType> list=materialTypeService.findMaterialTypeByCondition(map); |
|||
return new RestResponse(list,materialTypeService.findMaterialTypeCountByCondition(map),200); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 根据父级查询所有物料类型 |
|||
* @param param |
|||
* @return |
|||
*/ |
|||
@GetMapping("/allMaterialTypeByParent") |
|||
public RestResponse findMaterialTypeByNoParent(@RequestParam Map<String,Object> param){ |
|||
String parentId = (String) param.get("parentId"); |
|||
if (parentId == null ||"".equals(parentId)) { |
|||
parentId = "0"; |
|||
} |
|||
param.put("parentId",parentId); |
|||
List<MaterialType> list = materialTypeService.findMaterialTypeByCondition(param); |
|||
return new RestResponse(list,materialTypeService.findMaterialTypeCountByCondition(param),200); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 彻底删除物料类别 |
|||
* @param map |
|||
* @return |
|||
*/ |
|||
@PostMapping("/realDeleteMaterialType") |
|||
public RestResponse realDeleteMaterialType(@RequestBody Map<String,Object> map){ |
|||
if (map.containsKey("id")){ |
|||
Integer id= ObjectFormatUtil.toInteger(map.get("id")); |
|||
MaterialType materialTypeById = materialTypeService.findMaterialTypeById(id); |
|||
HandlesOtherFunctionalThreadPool.execute(() -> RealDeleteSonDepository(materialTypeById.getOldId().toString())); |
|||
|
|||
Integer integer = materialTypeService.deleteMaterialTypeById(id); |
|||
|
|||
HandlesOtherFunctionalThreadPool.execute(() -> { |
|||
try { |
|||
Thread.sleep(3000); |
|||
} catch (InterruptedException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
materialService.RefreshInitTreeMenus(); |
|||
}); |
|||
|
|||
return CrudUtil.deleteHandle(integer,1); |
|||
}else if (map.containsKey("ids")){ |
|||
List<Object> ids=(List<Object>) map.get("ids"); |
|||
for (Object id : ids) { |
|||
MaterialType materialTypeById = materialTypeService.findMaterialTypeById(id); |
|||
HandlesOtherFunctionalThreadPool.execute(() -> RealDeleteSonDepository(materialTypeById.getOldId().toString())); |
|||
} |
|||
|
|||
|
|||
Integer integer = materialTypeService.deleteMaterialTypeByIds(ids); |
|||
|
|||
|
|||
HandlesOtherFunctionalThreadPool.execute(() -> { |
|||
try { |
|||
Thread.sleep(3000); |
|||
} catch (InterruptedException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
materialService.RefreshInitTreeMenus(); |
|||
}); |
|||
return CrudUtil.deleteHandle(integer,ids.size()); |
|||
}else { |
|||
throw new MyException("所需请求参数缺失!"); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 删除所有子物料类型信息(硬删除) |
|||
* @param parentId |
|||
*/ |
|||
public void RealDeleteSonDepository(String parentId){ |
|||
Map<String,Object> param = new HashMap<>(); |
|||
param.put("parentId",parentId); |
|||
// 获取当前仓库所有子仓库
|
|||
List<MaterialType> materialTypeByCondition = materialTypeService.findMaterialTypeByCondition(param); |
|||
for (MaterialType materialType : materialTypeByCondition) { |
|||
Long oldId = materialType.getOldId();// 获取当前物料id
|
|||
RealDeleteSonDepository(oldId.toString()); // 递归查询物料类型
|
|||
materialTypeService.deleteMaterialTypeById(ObjectFormatUtil.toInteger(oldId.toString())); // 删除物料类型
|
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 根据主键删除物料类型 |
|||
* @param map |
|||
* @return |
|||
*/ |
|||
@PostMapping("/materialType_del") |
|||
public RestResponse deleteMaterialType(@RequestBody Map<String,Object> map){ |
|||
if (map.containsKey("id")){ |
|||
Object id = map.get("id"); |
|||
MaterialType materialTypeById = materialTypeService.findMaterialTypeById(id); |
|||
HandlesOtherFunctionalThreadPool.execute(() -> UpdateSonState(materialTypeById.getOldId().toString(),3)); |
|||
|
|||
Integer integer = materialTypeService.changeStateToDeletedById(id); |
|||
|
|||
|
|||
HandlesOtherFunctionalThreadPool.execute(() -> { |
|||
try { |
|||
Thread.sleep(3000); |
|||
} catch (InterruptedException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
materialService.RefreshInitTreeMenus(); |
|||
}); |
|||
|
|||
return CrudUtil.deleteHandle(integer,1); |
|||
}else if (map.containsKey("ids")){ |
|||
List<Object> ids=(List<Object>) map.get("ids"); |
|||
for (Object id : ids) { |
|||
MaterialType materialTypeById = materialTypeService.findMaterialTypeById(id); |
|||
HandlesOtherFunctionalThreadPool.execute(() -> UpdateSonState(materialTypeById.getOldId().toString(), 3)); |
|||
} |
|||
|
|||
|
|||
Integer integer = materialTypeService.changeStateToDeletedByIds(ids); |
|||
|
|||
HandlesOtherFunctionalThreadPool.execute(() -> { |
|||
try { |
|||
Thread.sleep(3000); |
|||
} catch (InterruptedException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
materialService.RefreshInitTreeMenus(); |
|||
}); |
|||
|
|||
return CrudUtil.deleteHandle(integer,ids.size()); |
|||
}else { |
|||
throw new MyException("所需请求参数缺失!"); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 修改物料类型 |
|||
* @param map |
|||
* @return |
|||
*/ |
|||
@PostMapping("/materialType_edit") |
|||
public RestResponse updateMaterialType(@RequestBody Map<String,Object> map){ |
|||
if(map.containsKey("state")){ |
|||
map.put("state",1); |
|||
}else{ |
|||
map.put("state",2); |
|||
} |
|||
|
|||
Integer integer = materialTypeService.updateMaterialType(map); |
|||
|
|||
HandlesOtherFunctionalThreadPool.execute(() -> { |
|||
try { |
|||
Thread.sleep(1000); |
|||
} catch (InterruptedException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
materialService.RefreshInitTreeMenus(); |
|||
}); |
|||
return CrudUtil.insertHandle(integer,1); |
|||
} |
|||
|
|||
/** |
|||
* 查找该类型下内是否有物品 |
|||
* @param map |
|||
* @return |
|||
*/ |
|||
@PostMapping("/findMaterialByMaterialTypeId") |
|||
public RestResponse findMaterialByMaterialTypeId(@RequestBody Map<String, Object> map){ |
|||
Boolean allSonDepository = false; |
|||
if(map.containsKey("id")){ |
|||
Integer materialTypeId = ObjectFormatUtil.toInteger(map.get("id")); |
|||
MaterialType materialTypeById = materialTypeService.findMaterialTypeById(materialTypeId); |
|||
allSonDepository = findAllSonMaterialType(materialTypeById.getOldId().toString()); |
|||
}else if(map.containsKey("ids")){ |
|||
List<Integer> ids = (List<Integer>) map.get("ids"); |
|||
for (int i = 0; i < ids.size(); i++) { |
|||
MaterialType materialTypeById = materialTypeService.findMaterialTypeById(ids.get(i)); |
|||
allSonDepository |= findAllSonMaterialType(materialTypeById.getOldId().toString()); |
|||
if(allSonDepository){ |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
else { |
|||
throw new MyException("所需请求参数缺失!"); |
|||
} |
|||
return new RestResponse(allSonDepository); |
|||
} |
|||
|
|||
@GetMapping("/treeMenus") |
|||
public RestResponse InitTreeMenus(){ |
|||
List<Object> list = materialTypeService.InitTreeMenus(); |
|||
return new RestResponse(list); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 根据父级类型编号查询所有子类型 |
|||
* @param parentid |
|||
* @return |
|||
*/ |
|||
public Boolean findAllSonMaterialType(String parentid){ |
|||
Map<String,Object> param = new HashMap<>(); |
|||
param.put("parentId",parentid); |
|||
param.put("state",1); |
|||
boolean materialByMaterialType = findMaterialByMaterialType(parentid); |
|||
if(materialByMaterialType){ |
|||
return true; |
|||
} |
|||
List<MaterialType> materialTypeByCondition = materialTypeService.findMaterialTypeByCondition(param); |
|||
for (MaterialType materialType : materialTypeByCondition) { |
|||
if (!findMaterialByMaterialType(materialType.getOldId().toString())) { |
|||
findAllSonMaterialType(materialType.getOldId().toString()); |
|||
} else { |
|||
return true; |
|||
} |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
/** |
|||
* 根据类型编号判断该类型下是否有物品 |
|||
* @param parentId |
|||
* @return |
|||
*/ |
|||
public boolean findMaterialByMaterialType(String parentId){ |
|||
Map<String,Object> param = new HashMap<>(); |
|||
param.put("materialTypeId",parentId); |
|||
param.put("state",1); |
|||
List<MaterialP> materialPByCondition = materialService.findMaterialPByCondition(param); |
|||
if(materialPByCondition.size() > 0){ |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
/** |
|||
* 修改物料类型状态 |
|||
* @param map |
|||
* @return |
|||
*/ |
|||
@PostMapping("/EditMaterialTypeState") |
|||
public RestResponse EditMaterialTypeState(@RequestBody Map<String,Object> map){ |
|||
if (map.containsKey("state")) { |
|||
map.put("state", 1); |
|||
} else { |
|||
map.put("state", 2); |
|||
} |
|||
int state = ((int)map.get("state")); |
|||
String id = (String) map.get("id"); |
|||
MaterialType materialTypeById = materialTypeService.findMaterialTypeById(ObjectFormatUtil.toInteger(id)); |
|||
HandlesOtherFunctionalThreadPool.execute(() -> UpdateSonState(materialTypeById.getOldId().toString(), state)); |
|||
|
|||
|
|||
Integer integer = materialTypeService.updateMaterialType(map); |
|||
|
|||
HandlesOtherFunctionalThreadPool.execute(() -> { |
|||
try { |
|||
Thread.sleep(3000); |
|||
} catch (InterruptedException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
materialService.RefreshInitTreeMenus(); |
|||
}); |
|||
|
|||
return CrudUtil.insertHandle(integer, 1); |
|||
} |
|||
|
|||
/** |
|||
* 修改所有类型状态 |
|||
* @param parentId |
|||
* @param state |
|||
*/ |
|||
public void UpdateSonState(String parentId,Integer state){ |
|||
Map<String,Object> param = new HashMap<>(); |
|||
param.put("parentId",parentId); |
|||
// 将当前类型下的物品变为禁用
|
|||
UpdateSonMaterialState(parentId,state); |
|||
// 获取当前类型所有子类型
|
|||
List<MaterialType> materialTypeByCondition = materialTypeService.findMaterialTypeByCondition(param); |
|||
for (MaterialType materialType : materialTypeByCondition) { |
|||
Long materialTypeId = materialType.getId(); |
|||
Long oldId = materialType.getOldId(); |
|||
UpdateSonState(String.valueOf(oldId), state); |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("id", materialTypeId); |
|||
map.put("state", state); |
|||
materialTypeService.updateStateByParam(map); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 修改当前物料类型状态 |
|||
* @param parentId |
|||
* @param state |
|||
*/ |
|||
public void UpdateSonMaterialState(String parentId,Integer state){ |
|||
Map<String,Object> param = new HashMap<>(); |
|||
param.put("typeId",parentId); |
|||
param.put("state",state); |
|||
materialService.updateStateByTypeId(param); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,146 @@ |
|||
package com.dreamchaser.depository_manage.controller; |
|||
|
|||
import com.dreamchaser.depository_manage.entity.UserByPort; |
|||
import com.dreamchaser.depository_manage.exception.MyException; |
|||
import com.dreamchaser.depository_manage.pojo.NoticeP; |
|||
import com.dreamchaser.depository_manage.pojo.RestResponse; |
|||
import com.dreamchaser.depository_manage.security.pool.AuthenticationTokenPool; |
|||
import com.dreamchaser.depository_manage.service.NoticeService; |
|||
import com.dreamchaser.depository_manage.service.impl.QyWxOperationService; |
|||
import com.dreamchaser.depository_manage.utils.CrudUtil; |
|||
import com.dreamchaser.depository_manage.utils.Md5; |
|||
import com.dreamchaser.depository_manage.utils.ObjectFormatUtil; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @author Dreamchaser |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("/notice") |
|||
public class NoticeController { |
|||
|
|||
|
|||
@Autowired |
|||
NoticeService noticeService; |
|||
|
|||
@Autowired |
|||
QyWxOperationService qyWxOperationService; |
|||
|
|||
@PostMapping("/notice") |
|||
public RestResponse addNotice(@RequestBody Map<String, Object> map, HttpServletRequest request) { |
|||
String token = request.getHeader("user-token"); |
|||
if(token == null){ |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
} |
|||
UserByPort userByPort = AuthenticationTokenPool.getUserToken(token); |
|||
map.put("userId", userByPort.getId()); |
|||
|
|||
String header = request.getHeader("user-agent"); |
|||
String crypt = Md5.crypt(header); |
|||
|
|||
map.put("state", 1); |
|||
// 获取插入结果
|
|||
Integer integer = noticeService.addNotice(map,crypt); |
|||
if (Integer.compare(integer, 1) == 0) { |
|||
// 开启线程推送应用消息
|
|||
/*HandlesOtherfunctionalThreadPool.execute(() -> qyWxOperationService.sendNoticeForAllUser(ObjectFormatUtil.toInteger(map.get("id")),crypt));*/ |
|||
|
|||
} |
|||
return CrudUtil.insertHandle(integer, 1); |
|||
} |
|||
|
|||
@GetMapping("/findAllNotices") |
|||
public RestResponse findNotices(@RequestParam Map<String, Object> map, HttpServletRequest request) { |
|||
String token = request.getHeader("user-token"); |
|||
String userKey = request.getHeader("user-key"); |
|||
if(token == null){ |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
userKey = (String) request.getSession().getAttribute("userKey"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
String header = request.getHeader("user-agent"); |
|||
String crypt = Md5.crypt(header); |
|||
map.put("userAgent", crypt); |
|||
List<NoticeP> noticeByCondition = noticeService.findAllNoticeForUser(map, userToken,userKey,token); |
|||
return new RestResponse(noticeByCondition); |
|||
} |
|||
|
|||
@PostMapping("/notice_del") |
|||
public RestResponse DelNotice(@RequestBody Map<String, Object> map, HttpServletRequest request) { |
|||
if(map.containsKey("id")){ |
|||
Long id = ObjectFormatUtil.toLong(map.get("id")); |
|||
Integer integer = noticeService.delNoticeForSoftById(id); |
|||
return CrudUtil.deleteHandle(integer,1); |
|||
}else if(map.containsKey("ids")){ |
|||
List<Long> ids = ObjectFormatUtil.objToList(map.get("ids"),Long.class); |
|||
Integer integer = noticeService.delNoticeForSoftByIds(ids); |
|||
return CrudUtil.deleteHandle(integer,ids.size()); |
|||
}else{ |
|||
throw new MyException("缺少必要参数"); |
|||
} |
|||
} |
|||
|
|||
@PostMapping("/readNoticeForUser") |
|||
public void readNoticeForUser(@RequestBody Map<String,Object> map,HttpServletRequest request){ |
|||
if(map.containsKey("id")){ |
|||
noticeService.readNoticeForUser(map); |
|||
}else{ |
|||
throw new MyException("缺少必要参数"); |
|||
} |
|||
} |
|||
|
|||
|
|||
// 用于修改公告信息
|
|||
@PostMapping("/noticeEdit") |
|||
public RestResponse noticeEdit(@RequestBody Map<String, Object> map, HttpServletRequest request) { |
|||
if (map.containsKey("id")) { |
|||
Integer integer = noticeService.updateNotice(map); |
|||
return CrudUtil.updateHandle(integer,1); |
|||
} else { |
|||
throw new MyException("缺少必要参数"); |
|||
} |
|||
} |
|||
|
|||
@PostMapping("/realDeleteNotice") |
|||
public RestResponse realDeleteNotice(@RequestBody Map<String,Object> map){ |
|||
if(map.containsKey("id")){ |
|||
Long id = ObjectFormatUtil.toLong(map.get("id")); |
|||
Integer integer = noticeService.delNoticeById(id); |
|||
return CrudUtil.deleteHandle(integer,1); |
|||
}else{ |
|||
throw new MyException("缺少必要参数"); |
|||
} |
|||
} |
|||
|
|||
@PostMapping("/EditNoticeState") |
|||
public RestResponse EditNoticeState(@RequestBody Map<String,Object> map){ |
|||
if(map.containsKey("id")){ |
|||
Integer integer = noticeService.updateNoticeState(map); |
|||
return CrudUtil.updateHandle(integer,1); |
|||
}else{ |
|||
throw new MyException("缺少必要参数"); |
|||
} |
|||
} |
|||
|
|||
@PostMapping("/noticeInfo") |
|||
public RestResponse noticeInfo(@RequestBody Map< String,Object> map,HttpServletRequest request){ |
|||
String token = request.getHeader("user-token"); |
|||
String userKey = request.getHeader("user-key"); |
|||
if(token == null){ |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
userKey = (String) request.getSession().getAttribute("userKey"); |
|||
} |
|||
if(map.containsKey("id")){ |
|||
NoticeP notice = noticeService.findNoticeById(ObjectFormatUtil.toLong(map.get("id")),userKey,token); |
|||
return new RestResponse(notice); |
|||
}else{ |
|||
throw new MyException("缺少必要参数"); |
|||
} |
|||
} |
|||
|
|||
} |
|||
File diff suppressed because it is too large
@ -0,0 +1,539 @@ |
|||
package com.dreamchaser.depository_manage.controller; |
|||
|
|||
import com.dreamchaser.depository_manage.entity.*; |
|||
import com.dreamchaser.depository_manage.entity.MaterialAndPlace; |
|||
import com.dreamchaser.depository_manage.exception.MyException; |
|||
import com.dreamchaser.depository_manage.pojo.*; |
|||
import com.dreamchaser.depository_manage.security.pool.AuthenticationTokenPool; |
|||
import com.dreamchaser.depository_manage.service.DepositoryService; |
|||
import com.dreamchaser.depository_manage.service.MaterialService; |
|||
import com.dreamchaser.depository_manage.service.PlaceService; |
|||
import com.dreamchaser.depository_manage.service.RoleService; |
|||
import com.dreamchaser.depository_manage.utils.CrudUtil; |
|||
import com.dreamchaser.depository_manage.utils.ObjectFormatUtil; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import java.io.IOException; |
|||
import java.util.*; |
|||
|
|||
@RestController |
|||
@RequestMapping("/place") |
|||
public class PlaceController { |
|||
@Autowired |
|||
PlaceService placeService; |
|||
|
|||
@Autowired |
|||
MaterialService materialService; |
|||
|
|||
@Autowired |
|||
DepositoryService depositoryService; |
|||
|
|||
@Autowired |
|||
RoleService roleService; |
|||
|
|||
/** |
|||
* 根据条件查询库位 |
|||
* |
|||
* @param map |
|||
* @return |
|||
*/ |
|||
@GetMapping("/findPlace") |
|||
public RestResponse findMaterial(@RequestParam Map<String, Object> map) { |
|||
List<Place> placeByCondition = placeService.findPlaceByCondition(map); |
|||
List<PlaceP> placePList = new ArrayList<>(); |
|||
for (Place place : placeByCondition) { |
|||
PlaceP placeP = new PlaceP(place); |
|||
Long depositoryId = place.getDid(); |
|||
Depository depositoryById = depositoryService.findDepositoryById(depositoryId); |
|||
// 获取当前库位所有的物料信息
|
|||
List<MaterialAndPlace> placeAndMaterialByPid = placeService.findPlaceAndMaterialByPid(place.getId()); |
|||
if (placeAndMaterialByPid == null) { |
|||
placeAndMaterialByPid = new ArrayList<>(); |
|||
} |
|||
StringBuilder mname = new StringBuilder(); |
|||
for (MaterialAndPlace materialAndPlace : placeAndMaterialByPid) { |
|||
Long mid = materialAndPlace.getMid(); |
|||
Inventory materialById = materialService.findInventoryById(mid); |
|||
mname.append(materialById.getMname()).append(","); |
|||
} |
|||
placeP.setMaterialAndPlaceList(placeAndMaterialByPid); |
|||
placeP.setMname(mname.toString()); |
|||
if (depositoryById != null) { |
|||
placeP.setDepositoryName(depositoryById.getDname()); |
|||
placeP.setDepositoryCode(depositoryById.getCode()); |
|||
} |
|||
placePList.add(placeP); |
|||
} |
|||
return new RestResponse(placePList, placeService.findPlaceCountByCondition(map), 200); |
|||
} |
|||
|
|||
/** |
|||
* 用于创建库位 |
|||
* |
|||
* @param map |
|||
* @return |
|||
*/ |
|||
@PostMapping("/addPlace") |
|||
public RestResponse insertPlace(@RequestBody Map<String, Object> map) { |
|||
String type = (String) map.get("type"); |
|||
Map<String, Object> insert = new HashMap<>(); |
|||
Integer success = 0; |
|||
int total = 0; |
|||
if ("one".equals(type)) { |
|||
Integer place_x = ObjectFormatUtil.toInteger(map.get("place_x")); |
|||
// Integer place_y = ObjectFormatUtil.toInteger(map.get("place_y"));
|
|||
Integer place_z = ObjectFormatUtil.toInteger(map.get("place_z")); |
|||
String min = (String) map.get("min"); |
|||
String max = (String) map.get("max"); |
|||
// String code = String.format("%02d", place_x) + String.format("%02d", place_y) + String.format("%02d", place_z);
|
|||
String code = String.format("%02d", place_x) + String.format("%02d", place_z); |
|||
insert.put("x", place_x); |
|||
// insert.put("y", place_y);
|
|||
insert.put("z", place_z); |
|||
insert.put("code", code); |
|||
Depository depository = depositoryService.findDepositoryById(ObjectFormatUtil.toLong(map.get("depositoryId"))); |
|||
String depositoryCode = depository.getCode(); |
|||
String kingdeeCode = depositoryCode.substring(depositoryCode.length() - 2) + code; |
|||
insert.put("did", map.get("depositoryId")); |
|||
insert.put("kingdeecode", kingdeeCode); |
|||
if (!"".equals(min)) { |
|||
insert.put("min", map.get("min")); |
|||
} else { |
|||
insert.put("min", 0); |
|||
} |
|||
if (!"".equals(max)) { |
|||
Double maxQuantity = ObjectFormatUtil.toDouble(max); |
|||
maxQuantity *= 100; |
|||
if (maxQuantity >= 999999999) { |
|||
insert.put("max", 999999999); |
|||
} else { |
|||
insert.put("max", maxQuantity); |
|||
} |
|||
} else { |
|||
insert.put("max", 0); |
|||
} |
|||
insert.put("state", 1); |
|||
insert.put("quantity", 0); |
|||
insert.put("flagType", 1); |
|||
success += placeService.InsertPlace(insert); |
|||
} else if ("list".equals(type)) { |
|||
//获取起始、终止行
|
|||
Integer place_start_x = ObjectFormatUtil.toInteger(map.get("place_start_x")); |
|||
Integer place_end_x = ObjectFormatUtil.toInteger(map.get("place_end_x")); |
|||
//获取起始、终止列
|
|||
// Integer place_start_y = ObjectFormatUtil.toInteger(map.get("place_start_y"));
|
|||
// Integer place_end_y = ObjectFormatUtil.toInteger(map.get("place_end_y"));
|
|||
//获取起始、终止层
|
|||
Integer place_start_z = ObjectFormatUtil.toInteger(map.get("place_start_z")); |
|||
Integer place_end_z = ObjectFormatUtil.toInteger(map.get("place_end_z")); |
|||
// 计算所需库位数目
|
|||
// total = (place_end_x - place_start_x) * (place_end_y - place_start_y) * (place_end_z - place_start_z);
|
|||
total = (place_end_x - place_start_x + 1) * (place_end_z - place_start_z + 1); |
|||
String min = (String) map.get("min"); |
|||
String max = (String) map.get("max"); |
|||
Depository depository = depositoryService.findDepositoryById(ObjectFormatUtil.toLong(map.get("depositoryId"))); |
|||
String depositoryCode = depository.getCode(); |
|||
for (int i = place_start_x; i <= place_end_x; i++) { |
|||
// for (int j = place_start_y; j < place_end_y; j++) {
|
|||
for (int k = place_start_z; k <= place_end_z; k++) { |
|||
// String code = String.format("%02d", i) + String.format("%02d", j) + String.format("%02d", k);
|
|||
String code = String.format("%02d", i) + String.format("%02d", k); |
|||
insert.put("x", i); |
|||
// insert.put("y",j);
|
|||
insert.put("z", k); |
|||
insert.put("code", code); |
|||
String kingdeeCode = depositoryCode.substring(depositoryCode.length() - 2) + code; |
|||
insert.put("did", map.get("depositoryId")); |
|||
insert.put("kingdeecode", kingdeeCode); |
|||
insert.put("min", min); |
|||
Double maxQuantity = ObjectFormatUtil.toDouble(max); |
|||
maxQuantity *= 100; |
|||
if (maxQuantity >= 999999999) { |
|||
insert.put("max", 999999999); |
|||
} else { |
|||
insert.put("max", maxQuantity); |
|||
} |
|||
insert.put("state", 1); |
|||
insert.put("quantity", 0); |
|||
insert.put("flagType", 1); |
|||
success += placeService.InsertPlace(insert); |
|||
} |
|||
// }
|
|||
} |
|||
} else { |
|||
throw new MyException("所需请求参数缺失!"); |
|||
} |
|||
|
|||
if ("one".equals(type)) { |
|||
return CrudUtil.insertHandle(success, 1); |
|||
} else if ("list".equals(type)) { |
|||
return CrudUtil.insertHandle(success, total); |
|||
} else { |
|||
throw new MyException("请求参数错误!"); |
|||
} |
|||
} |
|||
|
|||
|
|||
@PostMapping("/addTray") |
|||
public RestResponse addTray(@RequestBody Map<String, Object> map) { |
|||
String type = (String) map.get("type"); |
|||
Map<String, Object> insert = new HashMap<>(); |
|||
Integer success = 0; |
|||
Integer total = 0; |
|||
String min = (String) map.get("min"); |
|||
String max = (String) map.get("max"); |
|||
if (!"".equals(min)) { |
|||
insert.put("min", map.get("min")); |
|||
} else { |
|||
insert.put("min", 0); |
|||
} |
|||
if (!"".equals(max)) { |
|||
Double maxQuantity = ObjectFormatUtil.toDouble(max); |
|||
maxQuantity *= 100; |
|||
if (maxQuantity >= 999999999) { |
|||
insert.put("max", 999999999); |
|||
} else { |
|||
insert.put("max", maxQuantity); |
|||
} |
|||
} else { |
|||
insert.put("max", 0); |
|||
} |
|||
Object depositoryId = map.get("depositoryId"); |
|||
insert.put("did", depositoryId); |
|||
// 获取当前仓库的托盘数量
|
|||
Integer countForTray = placeService.findPlaceCountByTypeForFlag(2, ObjectFormatUtil.toLong(depositoryId)); |
|||
if ("one".equals(type)) { |
|||
String code = "F" + String.format("%02d", countForTray + 1); |
|||
insert.put("code", code); |
|||
insert.put("state", 1); |
|||
insert.put("quantity", 0); |
|||
insert.put("flagType", 2); |
|||
success += placeService.InsertPlace(insert); |
|||
} else if ("list".equals(type)) { |
|||
Integer num = ObjectFormatUtil.toInteger(map.get("num")); |
|||
insert.put("state", 1); |
|||
insert.put("quantity", 0); |
|||
insert.put("flagType", 2); |
|||
total = num; |
|||
for (int i = 1; i <= num; i++) { |
|||
String code = "F" + String.format("%02d", countForTray + i); |
|||
insert.put("code", code); |
|||
success += placeService.InsertPlace(insert); |
|||
} |
|||
} |
|||
if ("one".equals(type)) { |
|||
return CrudUtil.insertHandle(success, 1); |
|||
} else if ("list".equals(type)) { |
|||
return CrudUtil.insertHandle(success, total); |
|||
} else { |
|||
throw new MyException("请求参数错误!"); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 将库位状态改为删除 |
|||
* |
|||
* @param map |
|||
* @return |
|||
*/ |
|||
@PostMapping("/deletePlace") |
|||
public RestResponse deletePlace(@RequestBody Map<String, Object> map) { |
|||
if (map.containsKey("id")) { |
|||
Long id = ObjectFormatUtil.toLong(map.get("id")); |
|||
return CrudUtil.deleteHandle(placeService.changeStateToDeletedById(id), 1); |
|||
} else if (map.containsKey("ids")) { |
|||
List<Long> ids = ObjectFormatUtil.objToList(map.get("ids"),Long.class); |
|||
return CrudUtil.deleteHandle(placeService.changeStateToDeletedByIds(ids), ids.size()); |
|||
} else { |
|||
throw new MyException("所需请求参数缺失!"); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 修改库位信息 |
|||
*/ |
|||
@PostMapping("/place_edit") |
|||
public RestResponse placeEdit(@RequestBody Map<String, Object> map) { |
|||
if (map.containsKey("state")) { |
|||
map.put("state", 1); |
|||
} else { |
|||
map.put("state", 2); |
|||
} |
|||
Object id = map.get("id"); |
|||
// 获取当前修改的库位
|
|||
Place placeById = placeService.findPlaceById(ObjectFormatUtil.toLong(id)); |
|||
Map<String, Object> update = new HashMap<>(); |
|||
Integer place_x = ObjectFormatUtil.toInteger(map.get("place_x")); |
|||
// Integer place_y = ObjectFormatUtil.toInteger(map.get("place_y"));
|
|||
Integer place_z = ObjectFormatUtil.toInteger(map.get("place_z")); |
|||
String newCode = ""; |
|||
if (Integer.compare(placeById.getX(), place_x) != 0 || Integer.compare(placeById.getZ(), place_z) != 0) { |
|||
// 如果更改了行层
|
|||
// String code = String.format("%02d", place_x) + String.format("%02d", place_y) + String.format("%02d", place_z);
|
|||
newCode = String.format("%02d", place_x) + String.format("%02d", place_z); |
|||
} else { |
|||
newCode = (String) map.get("code"); |
|||
} |
|||
String oldCode = placeById.getCode(); |
|||
if (!newCode.equals(oldCode)) { |
|||
// 如果编码发生改变
|
|||
|
|||
// 获取当前修改后的库位编码是否存在
|
|||
Place placeByDidAndCode = placeService.findPlaceByDidAndCode(placeById.getDid(), newCode); |
|||
if (placeByDidAndCode != null) { |
|||
// 如果存在
|
|||
return new RestResponse("", 12345, new StatusInfo("修改失败", "该编码或位置已经存在")); |
|||
} |
|||
} |
|||
String min = (String) map.get("min"); |
|||
String max = (String) map.get("max"); |
|||
update.put("x", place_x); |
|||
// update.put("y", place_y);
|
|||
update.put("z", place_z); |
|||
update.put("code", newCode); |
|||
update.put("kingdeecode", placeById.getKingdeecode().substring(0, 2) + newCode); |
|||
update.put("oldCode", oldCode); |
|||
update.put("did", map.get("did")); |
|||
if (!"".equals(min)) { |
|||
update.put("min", map.get("min")); |
|||
} else { |
|||
update.put("min", 0); |
|||
} |
|||
if (!"".equals(max)) { |
|||
Double maxQuantity = ObjectFormatUtil.toDouble(max); |
|||
if (maxQuantity >= 999999999) { |
|||
update.put("max", 999999999); |
|||
} else { |
|||
update.put("max", map.get("max")); |
|||
} |
|||
} else { |
|||
update.put("max", 50000); |
|||
} |
|||
update.put("id", id); |
|||
return CrudUtil.insertHandle(placeService.UpdatePlace(update), 1); |
|||
} |
|||
|
|||
@PostMapping("/tray_edit") |
|||
public RestResponse trayEdit(@RequestBody Map<String, Object> map) { |
|||
if (!map.containsKey("id")) { |
|||
throw new MyException("缺少必要参数"); |
|||
} |
|||
Long id = ObjectFormatUtil.toLong(map.get("id")); |
|||
if (map.containsKey("state")) { |
|||
map.put("state", 1); |
|||
} else { |
|||
map.put("state", 2); |
|||
} |
|||
String code = (String) map.get("code"); |
|||
Place placeById = placeService.findPlaceById(id); |
|||
Map<String, Object> update = new HashMap<>(); |
|||
if (!code.equals(placeById.getCode())) { |
|||
Long depositoryId = ObjectFormatUtil.toLong(map.get("did")); |
|||
Place placeByDidAndCode = placeService.findPlaceByDidAndCode(depositoryId, code); |
|||
if (placeByDidAndCode == null) { |
|||
update.put("code", code); |
|||
} else { |
|||
return new RestResponse("", 12345, new StatusInfo("修改失败", "该编码已经存在")); |
|||
} |
|||
} |
|||
|
|||
String min = (String) map.get("min"); |
|||
String max = (String) map.get("max"); |
|||
if (!"".equals(min)) { |
|||
update.put("min", map.get("min")); |
|||
} else { |
|||
update.put("min", 0); |
|||
} |
|||
if (!"".equals(max)) { |
|||
Double maxQuantity = ObjectFormatUtil.toDouble(max); |
|||
if (maxQuantity >= 999999999) { |
|||
update.put("max", 999999999); |
|||
} else { |
|||
update.put("max", map.get("max")); |
|||
} |
|||
} else { |
|||
update.put("max", 50000); |
|||
} |
|||
|
|||
update.put("id", id); |
|||
return CrudUtil.insertHandle(placeService.UpdatePlace(update), 1); |
|||
} |
|||
|
|||
|
|||
@PostMapping("/editPlaceState") |
|||
public RestResponse editPlaceState(@RequestBody Map<String, Object> map) { |
|||
if (map.containsKey("state")) { |
|||
map.put("state", 1); |
|||
} else { |
|||
map.put("state", 2); |
|||
} |
|||
return CrudUtil.insertHandle(placeService.editPlaceState(map), 1); |
|||
} |
|||
|
|||
// 根据物料编号获取库位
|
|||
@PostMapping("/findPlaceByMid") |
|||
public RestResponse findPlaceByMid(@RequestBody Map<String, Object> map, HttpServletRequest request) { |
|||
String token = request.getHeader("user-token"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
// 查询当前用户部门所拥有的仓库
|
|||
List<Depository> depositoryByAdminorg = depositoryService.findDepositoryByAdminorg(userToken.getMaindeparment().toString()); |
|||
// 查询当前用户管理的仓库
|
|||
List<RoleAndDepository> depositoryAndRole = roleService.findDepositoryAndRole(userToken.getId()); |
|||
depositoryAndRole.addAll(roleService.findDepositoryAndRole(userToken.getPosition())); |
|||
Long mid = ObjectFormatUtil.toLong(map.get("mid")); |
|||
Inventory inventoryById = materialService.findInventoryById(mid); |
|||
List<PlaceP> placeList = new ArrayList<>(); |
|||
Map<String, Object> param = new HashMap<>(); |
|||
param.put("mcode", inventoryById.getCode()); |
|||
List<Long> depositoryIdList = new ArrayList<>(); |
|||
for (Depository depository : depositoryByAdminorg) { |
|||
depositoryIdList.add(depository.getId()); |
|||
} |
|||
for (RoleAndDepository depository : depositoryAndRole) { |
|||
if (!depositoryIdList.contains(depository.getDepositoryId())) { |
|||
depositoryIdList.add(depository.getDepositoryId()); |
|||
} |
|||
} |
|||
List<InventoryP> inventoryPList = new ArrayList<>(); |
|||
for (Long depositoryId : depositoryIdList |
|||
) { |
|||
param.put("depositoryId", depositoryId); |
|||
// 查找当前用户部门仓库中是否存在该物料
|
|||
inventoryPList.addAll(materialService.findInventory(param)); |
|||
} |
|||
for (Long depositoryId : depositoryIdList) { |
|||
for (InventoryP inventory : inventoryPList) { |
|||
List<PlaceP> placeByMidAndDid = placeService.findPlaceByMidAndDid(inventory.getId(), depositoryId); |
|||
for (PlaceP placeP : placeByMidAndDid) { |
|||
int index = placeList.indexOf(placeP); |
|||
if (index == -1) { |
|||
placeList.add(placeP); |
|||
} |
|||
} |
|||
} |
|||
|
|||
} |
|||
return new RestResponse(placeList); |
|||
} |
|||
|
|||
// 根据物料编码以及仓库编号获取具体库位
|
|||
@PostMapping("/findPlaceByMcodeAndDid") |
|||
public RestResponse findPlaceByMcodeAndDid(@RequestBody Map<String, Object> map, HttpServletRequest request) { |
|||
List<InventoryP> inventory = materialService.findInventory(map); |
|||
List<PlaceP> placeList = new ArrayList<>(); |
|||
if (inventory.size() > 0) { // 如果有当前物料
|
|||
for (int i = 0; i < inventory.size(); i++) { |
|||
InventoryP materialP = inventory.get(i); |
|||
List<PlaceP> placeByMidAndDid = placeService.findPlaceByMidAndDid(materialP.getId(), ObjectFormatUtil.toLong(map.get("depositoryId"))); |
|||
for (int j = 0; j < placeByMidAndDid.size(); j++) { |
|||
int index = placeList.indexOf(placeByMidAndDid.get(j)); |
|||
if (index == -1) { |
|||
placeList.add(placeByMidAndDid.get(j)); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
return new RestResponse(placeList); |
|||
} |
|||
|
|||
// 构造仓库二维码
|
|||
@PostMapping("/createQrCode") |
|||
public RestResponse createQrCode(@RequestBody Map<String, Object> map) { |
|||
|
|||
|
|||
Long pid = ObjectFormatUtil.toLong(map.get("pid")); |
|||
String qrCode = placeService.findQrCodeByPlace(pid); |
|||
try { |
|||
// 二维码保存信息
|
|||
Place placeById = placeService.findPlaceById(pid); |
|||
Depository depositoryById = depositoryService.findDepositoryById(placeById.getDid()); |
|||
return RestResponse.CreateBarCode(qrCode, depositoryById.getDname() + "-" + placeById.getCode()); |
|||
} catch (IOException e) { |
|||
return new RestResponse("err: " + e.getMessage(), 678, new StatusInfo("失败", "请联系开发人员")); |
|||
} |
|||
|
|||
} |
|||
|
|||
// 用于扫描入库位置
|
|||
@PostMapping("/qywxApplicationInScanQrCode") |
|||
public RestResponse qywxApplicationInScanQrCode(@RequestBody Map<String, Object> map, HttpServletRequest request) { |
|||
// 获取扫描的码值
|
|||
String qrCode = (String) map.get("qrCode"); |
|||
// 根据二维码获取对应位置信息
|
|||
PidOrDidAndCode locationByQrCode = placeService.findLocationByQrCode(qrCode); |
|||
Map<String, Object> result = new HashMap<>(); |
|||
result.put("flag", 0); |
|||
if (locationByQrCode != null) { |
|||
// 获取当前标志位(1为库位2为仓库)
|
|||
Integer flag = locationByQrCode.getFlag(); |
|||
if (Integer.compare(1, flag) == 0) { |
|||
// 如果当前位置为库位
|
|||
|
|||
// 获取当前库位
|
|||
Place place = placeService.findPlaceById(ObjectFormatUtil.toLong(locationByQrCode.getPid().toString())); |
|||
PlaceP placeP = new PlaceP(place); |
|||
|
|||
if (Long.compare(0, placeP.getId()) == 0) { |
|||
// 如果是默认库位
|
|||
placeP.setDepositoryName("默认库位-0000"); |
|||
} else { |
|||
Depository depository = depositoryService.findDepositoryById(placeP.getDid()); |
|||
placeP.setDepositoryName(depository.getDname() + "-" + placeP.getCode()); |
|||
} |
|||
result.put("flag", 1); |
|||
result.put("place", placeP); |
|||
} else { |
|||
// 如果当前位置为仓库
|
|||
|
|||
// 获取当前仓库
|
|||
Depository depository = depositoryService.findDepositoryById(ObjectFormatUtil.toLong(locationByQrCode.getDepositoryId().toString())); |
|||
result.put("flag", 2); |
|||
result.put("depository", depository); |
|||
} |
|||
} |
|||
return new RestResponse(result); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 获取当前位置信息 |
|||
* |
|||
* @param map |
|||
* @return |
|||
*/ |
|||
@PostMapping("/findLocationById") |
|||
public RestResponse findLocationById(@RequestBody Map<String, String> map) { |
|||
if (map.containsKey("id") && map.containsKey("type")) { |
|||
String type = map.get("type"); |
|||
String id = map.get("id"); |
|||
if ("d".equals(type)) { |
|||
// 如果是仓库
|
|||
Depository depositoryById = depositoryService.findDepositoryById(ObjectFormatUtil.toLong(id)); |
|||
return new RestResponse(depositoryById); |
|||
} else if ("p".equals(type)) { |
|||
// 如果是库位
|
|||
Place placeById = placeService.findPlaceById(ObjectFormatUtil.toLong(id)); |
|||
if (placeById != null) { |
|||
PlaceP placeP = new PlaceP(placeById); |
|||
Depository depositoryById = depositoryService.findDepositoryById(placeById.getDid()); |
|||
placeP.setDepositoryName(depositoryById.getDname()); |
|||
placeP.setDepositoryCode(depositoryById.getCode()); |
|||
return new RestResponse(placeP); |
|||
} else { |
|||
return new RestResponse(placeById); |
|||
} |
|||
} else { |
|||
return new RestResponse(null); |
|||
} |
|||
} else { |
|||
throw new MyException("缺少必要参数"); |
|||
} |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,740 @@ |
|||
package com.dreamchaser.depository_manage.controller; |
|||
|
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.dreamchaser.depository_manage.config.PublicConfig; |
|||
import com.dreamchaser.depository_manage.config.QyWxConfig; |
|||
import com.dreamchaser.depository_manage.config.QyWxJMJM.com.qq.weixin.mp.aes.AesException; |
|||
import com.dreamchaser.depository_manage.config.QyWxJMJM.com.qq.weixin.mp.aes.WXBizMsgCrypt; |
|||
import com.dreamchaser.depository_manage.entity.CallBackLog; |
|||
import com.dreamchaser.depository_manage.entity.UserByPort; |
|||
import com.dreamchaser.depository_manage.pojo.ApplicationOutRecordP; |
|||
import com.dreamchaser.depository_manage.pojo.RestResponse; |
|||
import com.dreamchaser.depository_manage.pojo.callBackXml.approvalCallBackXml.*; |
|||
import com.dreamchaser.depository_manage.pojo.callBackXml.callBackXml_button_templatecard.TemplateCard; |
|||
import com.dreamchaser.depository_manage.security.pool.AuthenticationTokenPool; |
|||
import com.dreamchaser.depository_manage.security.pool.HandlesOtherFunctionalThreadPool; |
|||
import com.dreamchaser.depository_manage.security.pool.RedisPool; |
|||
import com.dreamchaser.depository_manage.service.*; |
|||
import com.dreamchaser.depository_manage.service.impl.QyWxOperationService; |
|||
import com.dreamchaser.depository_manage.utils.EncryptionAlgorithmUtil; |
|||
import com.dreamchaser.depository_manage.utils.Md5; |
|||
import com.dreamchaser.depository_manage.utils.ObjectFormatUtil; |
|||
import com.dreamchaser.depository_manage.utils.QyWxXMLUtils; |
|||
import org.apache.commons.codec.digest.DigestUtils; |
|||
import org.apache.xmlbeans.impl.store.Public2; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Controller; |
|||
import org.springframework.web.bind.annotation.*; |
|||
import org.springframework.web.servlet.ModelAndView; |
|||
|
|||
import javax.annotation.Resource; |
|||
import javax.servlet.http.HttpServletRequest; |
|||
import javax.servlet.http.HttpServletResponse; |
|||
import javax.servlet.http.HttpSession; |
|||
import java.io.IOException; |
|||
import java.io.PrintWriter; |
|||
import java.time.Instant; |
|||
import java.util.*; |
|||
import java.util.concurrent.TimeUnit; |
|||
|
|||
|
|||
/** |
|||
* 用于企业微信相关操作的控制器 |
|||
*/ |
|||
@Controller |
|||
public class QyWxOperationController { |
|||
|
|||
|
|||
@Autowired |
|||
private CallBackLogService callBackLogService; |
|||
|
|||
|
|||
@Autowired |
|||
private QyWxOperationService qyWxOperationService; |
|||
|
|||
|
|||
@Autowired |
|||
private DepositoryRecordService depositoryRecordService; |
|||
|
|||
|
|||
@Autowired |
|||
private DepositoryService depositoryService; |
|||
|
|||
|
|||
@Autowired |
|||
private StockTakingService stockTakingService; |
|||
|
|||
|
|||
@Autowired |
|||
private RedisPool redisPool; |
|||
|
|||
@Autowired |
|||
private UserService userService; |
|||
|
|||
/** |
|||
* 用于接收企业微信的回调,get方式 |
|||
*/ |
|||
@GetMapping("/callback") |
|||
public void callBackForGet(@RequestParam Map<String, Object> map, HttpServletResponse response) { |
|||
try { |
|||
// 构造解密对象
|
|||
WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(QyWxConfig.sToken, QyWxConfig.sEncodingAESKey, QyWxConfig.corpid); |
|||
// 企业微信加密签名
|
|||
String sVerifyMsgSig = (String) map.get("msg_signature"); |
|||
// 时间戳
|
|||
Integer sVerifyTimeStamp = ObjectFormatUtil.toInteger(map.get("timestamp")); |
|||
// 随机数
|
|||
String sVerifyNonce = (String) map.get("nonce"); |
|||
// 加密的字符串
|
|||
String sVerifyEchoStr = (String) map.get("echostr"); |
|||
String sEchoStr; //需要返回的明文
|
|||
sEchoStr = wxcpt.VerifyURL(sVerifyMsgSig, sVerifyTimeStamp.toString(), |
|||
sVerifyNonce, sVerifyEchoStr); |
|||
|
|||
// 添加日志
|
|||
CallBackLog callBackLog = new CallBackLog(); |
|||
callBackLog.setTimestamp(sVerifyTimeStamp); |
|||
callBackLog.setNonce(sVerifyNonce); |
|||
callBackLog.setEchostr(sVerifyEchoStr); |
|||
callBackLogService.addCallBackLog(callBackLog); |
|||
|
|||
//返回明文
|
|||
PrintWriter writer = response.getWriter(); |
|||
writer.println(sEchoStr); |
|||
|
|||
System.out.println(sEchoStr); |
|||
} catch (AesException | IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 用于接收企业微信的回调,post方式 |
|||
*/ |
|||
@PostMapping("/callback") |
|||
public void callBackForPost(@RequestParam Map<String, Object> param, |
|||
@RequestBody(required = false) Map<String, Object> map, |
|||
HttpServletRequest request, HttpServletResponse response) { |
|||
try { |
|||
//本地调试用,生产环境接收的回调转发到本地环境 start
|
|||
|
|||
//本地调试用,生产环境接收的回调转发到本地环境 end
|
|||
|
|||
String header = request.getHeader("user-agent"); |
|||
String crypt = Md5.crypt(header); |
|||
// 构造解密对象
|
|||
WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(QyWxConfig.sToken, QyWxConfig.sEncodingAESKey, QyWxConfig.corpid); |
|||
// 企业微信加密签名
|
|||
String sVerifyMsgSig = (String) param.get("msg_signature"); |
|||
// 时间戳
|
|||
Integer sVerifyTimeStamp = ObjectFormatUtil.toInteger(param.get("timestamp")); |
|||
// 随机数
|
|||
String sVerifyNonce = (String) param.get("nonce"); |
|||
// 加密的字符串
|
|||
String sVerifyEchoStr = (String) param.get("echostr"); |
|||
|
|||
|
|||
if (sVerifyEchoStr != null) { |
|||
// 如果是验证url
|
|||
|
|||
String sEchoStr; //需要返回的明文
|
|||
sEchoStr = wxcpt.VerifyURL(sVerifyMsgSig, sVerifyTimeStamp.toString(), |
|||
sVerifyNonce, sVerifyEchoStr); |
|||
|
|||
// 添加日志
|
|||
CallBackLog callBackLog = new CallBackLog(); |
|||
callBackLog.setTimestamp(sVerifyTimeStamp); |
|||
callBackLog.setNonce(sVerifyNonce); |
|||
callBackLog.setEchostr(sVerifyEchoStr); |
|||
callBackLogService.addCallBackLog(callBackLog); |
|||
|
|||
//返回明文
|
|||
PrintWriter writer = response.getWriter(); |
|||
writer.println(sEchoStr); |
|||
writer.close(); |
|||
} |
|||
else { |
|||
// 如果是响应事件
|
|||
|
|||
String ToUserName = (String) map.get("ToUserName"); |
|||
String Encrypt = (String) map.get("Encrypt"); |
|||
String AgentID = (String) map.get("AgentID"); |
|||
|
|||
// 需要解密的xml
|
|||
String sReqData = String.format("<xml><ToUserName><![CDATA[%s]]></ToUserName>" + |
|||
"<Encrypt><![CDATA[%s]]></Encrypt>" + |
|||
"<AgentID><![CDATA[%s]]></AgentID></xml>", ToUserName, Encrypt, AgentID); |
|||
// 解析后的数据
|
|||
String sMsg = wxcpt.DecryptMsg(sVerifyMsgSig, sVerifyTimeStamp.toString(), sVerifyNonce, sReqData); |
|||
// 将数据转为java对象
|
|||
TemplateCard templateCard = (TemplateCard) QyWxXMLUtils.convertXmlStrToObject(TemplateCard.class, sMsg); |
|||
// 点击用户
|
|||
String fromUserName = templateCard.getFromUserName(); |
|||
if ("sys_approval_change".equals(templateCard.getEvent())) { |
|||
return; |
|||
} |
|||
// 根据userId获取处理人
|
|||
// Map<String, Object> portInfo = PublicConfig.findUserByQyWxUserId(fromUserName);
|
|||
// UserByPort userByPort = (UserByPort) portInfo.get("user");
|
|||
UserByPort userByPort = userService.findUserByWorkWechat(fromUserName); |
|||
|
|||
// 获取点击的按钮
|
|||
String clickKey = templateCard.getEventKey().split("_")[1]; |
|||
|
|||
// 获取点击卡片的类型
|
|||
String templateCardType = templateCard.getEventKey().split("_")[2]; |
|||
|
|||
|
|||
String result = ""; |
|||
if (clickKey.contains("pass")) { |
|||
result = "通过"; |
|||
} else { |
|||
result = "驳回"; |
|||
} |
|||
|
|||
if (templateCardType.contains("StockTaking")) { |
|||
// 如果点击的是库存盘点有关的卡片
|
|||
|
|||
String stockTakingType = templateCard.getEventKey().split("_")[1]; |
|||
|
|||
if (stockTakingType.contains("review")) { |
|||
// 开启线程处理审批
|
|||
HandlesOtherFunctionalThreadPool.execute(() -> { |
|||
Map<String, Object> reviewByQyWx = stockTakingService.reviewByQyWx(templateCard, crypt); |
|||
if (reviewByQyWx.containsKey("errMsg")) { |
|||
|
|||
} |
|||
}); |
|||
} else if (stockTakingType.contains("complete")) { |
|||
// 开启线程
|
|||
HandlesOtherFunctionalThreadPool.execute(() -> stockTakingService.completeStockTakingByQyWx(templateCard, crypt)); |
|||
} |
|||
|
|||
} else if (templateCardType.contains("out")) { |
|||
// 如果点击的是出库审核
|
|||
// 开启线程处理审批
|
|||
HandlesOtherFunctionalThreadPool.execute(() -> depositoryRecordService.reviewByQyWx(templateCard, crypt)); |
|||
} |
|||
|
|||
// 开启线程更改其他用户卡片模板样式
|
|||
String finalResult = result; |
|||
HandlesOtherFunctionalThreadPool.execute( |
|||
() -> |
|||
qyWxOperationService.updateButtonTemplateCardToUnEnable(templateCard.getResponseCode(), userByPort.getName(), finalResult, crypt)); |
|||
|
|||
// 待加密模板
|
|||
String sRespData = String.format("<xml><ToUserName><![CDATA[%s]]></ToUserName>" + |
|||
"<FromUserName><![CDATA[%s]]></FromUserName>" + |
|||
"<CreateTime>%s</CreateTime>" + |
|||
"<MsgType><![CDATA[update_button]]></MsgType>" + |
|||
"<Button>" + |
|||
"<ReplaceName><![CDATA[%s]]></ReplaceName></Button>" + |
|||
"</xml>", ToUserName, QyWxConfig.corpid, templateCard.getCreateTime(), "已" + result); |
|||
// 加密
|
|||
String sEncryptMsg = wxcpt.EncryptMsg(sRespData, sVerifyTimeStamp.toString(), sVerifyNonce); |
|||
//3.响应消息
|
|||
PrintWriter out = response.getWriter(); |
|||
out.print(sEncryptMsg); |
|||
out.close(); |
|||
} |
|||
} catch (AesException | IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于企业微信登录 |
|||
* |
|||
* @param code |
|||
* @param action |
|||
* @param state |
|||
* @param request |
|||
* @return |
|||
*/ |
|||
@GetMapping("/QyWxLogin") |
|||
public ModelAndView QyWxLogin(@RequestParam(required = false) String code, |
|||
@RequestParam(required = false) String action, |
|||
@RequestParam(required = false) String state, |
|||
HttpServletRequest request, |
|||
HttpServletResponse response) { |
|||
ModelAndView mv = new ModelAndView(); |
|||
mv.addObject("userWxId", ""); |
|||
mv.setViewName("pages/user/login"); |
|||
if (code != null) { |
|||
QyWxConfig.code = code; |
|||
String header = request.getHeader("user-agent"); |
|||
String crypt = Md5.crypt(header); |
|||
JSONObject jsonObject = QyWxConfig.GetQYWXUserId(crypt); |
|||
|
|||
Integer errCode = jsonObject.getInteger("errcode"); |
|||
String userId = jsonObject.getString("userid"); |
|||
if (errCode == 0) { |
|||
// 如果成功获取userid
|
|||
// Map<String, Object> portInfo = PublicConfig.findUserByQyWxUserId(userId);
|
|||
// UserByPort userByPort = (UserByPort) portInfo.get("user");
|
|||
UserByPort userByPort = userService.findUserByWorkWechat(userId); |
|||
|
|||
if (userByPort != null) { |
|||
|
|||
EncryptionAlgorithmUtil encryptionAlgorithmUtils = new EncryptionAlgorithmUtil(); |
|||
Map<String, String> userKeyAndUserToken = encryptionAlgorithmUtils.getUserKeyAndUserToken(userByPort); |
|||
String key = userKeyAndUserToken.get("key"); |
|||
String token = userKeyAndUserToken.get("token"); |
|||
|
|||
// 调用接口,用于写入数据至redis
|
|||
PublicConfig.findUserByQyWxUserId(userId); |
|||
|
|||
// 如果数据库中存在该用户
|
|||
// 设置放入时间
|
|||
userByPort.setInstant(Instant.now()); |
|||
AuthenticationTokenPool.addUserToken(token, userByPort); |
|||
HttpSession session = request.getSession(); |
|||
session.setAttribute("userToken", token); |
|||
session.setAttribute("userKey", key); |
|||
session.setMaxInactiveInterval(60 * 60 * 3); |
|||
try { |
|||
response.sendRedirect("https://jy.hxgk.group/"); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} else { |
|||
JSONObject captcha = PublicConfig.Captcha(request); |
|||
String picPath = (String) captcha.get("picPath"); |
|||
String captchaid = (String) captcha.get("captchaid"); |
|||
mv.addObject("picPath", picPath); |
|||
mv.addObject("captchaid", captchaid); |
|||
mv.addObject("userWxId", userId); |
|||
} |
|||
} else { |
|||
JSONObject captcha = PublicConfig.Captcha(request); |
|||
String picPath = (String) captcha.get("picPath"); |
|||
String captchaid = (String) captcha.get("captchaid"); |
|||
mv.addObject("picPath", picPath); |
|||
mv.addObject("captchaid", captchaid); |
|||
} |
|||
} else { |
|||
JSONObject captcha = PublicConfig.Captcha(request); |
|||
String picPath = (String) captcha.get("picPath"); |
|||
String captchaid = (String) captcha.get("captchaid"); |
|||
mv.addObject("picPath", picPath); |
|||
mv.addObject("captchaid", captchaid); |
|||
} |
|||
return mv; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于获取用于调用企业微信接口的签名 |
|||
* |
|||
* @param request |
|||
* @return |
|||
*/ |
|||
@GetMapping("/QyWxSignature") |
|||
@ResponseBody |
|||
public RestResponse getQyWXSignature(@RequestParam Map<String, String> map, HttpServletRequest request) { |
|||
// 随机字符串
|
|||
|
|||
|
|||
String token = request.getHeader("user-token"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
|
|||
|
|||
Map<String, String> result = new HashMap<>(); |
|||
// jsapi_ticket_app加密后
|
|||
String s = ""; |
|||
// jsapi_ticket_enterprises加密后
|
|||
String s1 = ""; |
|||
|
|||
// 时间戳
|
|||
long timestamp = 0; |
|||
|
|||
// 随机字符串
|
|||
String noncestr = ""; |
|||
|
|||
// 访问url
|
|||
String url = QyWxConfig.jsApiUrl; |
|||
|
|||
s = (String) redisPool.getRedisTemplateByDb(14).opsForHash().get("wms_QyWxScanQrCodeSignature", "jsapi_ticket_app"); |
|||
if (s != null) { |
|||
s1 = (String) redisPool.getRedisTemplateByDb(14).opsForHash().get("wms_QyWxScanQrCodeSignature", "jsapi_ticket_enterprises"); |
|||
timestamp = ObjectFormatUtil.toLong((String) Objects.requireNonNull(redisPool.getRedisTemplateByDb(14).opsForHash().get("wms_QyWxScanQrCodeSignature", "timestamp"))); |
|||
url = (String) redisPool.getRedisTemplateByDb(14).opsForHash().get("wms_QyWxScanQrCodeSignature", "url"); |
|||
noncestr = (String) redisPool.getRedisTemplateByDb(14).opsForHash().get("wms_QyWxScanQrCodeSignature", "noncestr"); |
|||
} else { |
|||
// 时间戳
|
|||
timestamp = System.currentTimeMillis() / 1000; |
|||
//生成从ASCII 32到126组成的随机字符串
|
|||
// String noncestr = RandomStringUtils.randomAscii(10);
|
|||
// 时间戳字符串
|
|||
noncestr = String.valueOf(timestamp); |
|||
|
|||
// 获取企业的jsapi_ticket
|
|||
|
|||
// user-agent加密
|
|||
String header = request.getHeader("user-agent"); |
|||
String crypt = Md5.crypt(header); |
|||
|
|||
JSONObject ticketForApp = QyWxConfig.getQyWxJsApiTicketForApp(crypt); |
|||
JSONObject ticketForEnterprise = QyWxConfig.getQyWxJsApiTicketForEnterprise(crypt); |
|||
Integer errcodeForEnterprise = ticketForEnterprise.getInteger("errcode"); |
|||
Integer errcodeForApp = ticketForApp.getInteger("errcode"); |
|||
// 获取企业的jsapi_ticket
|
|||
String ticketForEnterprises = ""; |
|||
String ticketForEnterApps = ""; |
|||
if (Integer.compare(0, errcodeForEnterprise) == 0) { |
|||
ticketForEnterprises = ticketForEnterprise.getString("ticket"); |
|||
} |
|||
if (Integer.compare(0, errcodeForApp) == 0) { |
|||
ticketForEnterApps = ticketForApp.getString("ticket"); |
|||
} |
|||
Integer expires_in = ticketForEnterprise.getInteger("expires_in"); |
|||
|
|||
// 步骤1. 将这些参数拼接成字符串string1:
|
|||
String jsapi_ticket_app = "jsapi_ticket=" + ticketForEnterApps + "&noncestr=" + noncestr + "×tamp=" + timestamp + "&url=" + url; |
|||
String jsapi_ticket_enterprises = "jsapi_ticket=" + ticketForEnterprises + "&noncestr=" + noncestr + "×tamp=" + timestamp + "&url=" + url; |
|||
// 步骤2. 对string1进行sha1签名,得到signature
|
|||
s = DigestUtils.sha1Hex(jsapi_ticket_app); |
|||
s1 = DigestUtils.sha1Hex(jsapi_ticket_enterprises); |
|||
|
|||
redisPool.getRedisTemplateByDb(14).opsForHash().put("wms_QyWxScanQrCodeSignature", "jsapi_ticket_app", s); |
|||
redisPool.getRedisTemplateByDb(14).opsForHash().put("wms_QyWxScanQrCodeSignature", "jsapi_ticket_enterprises", s1); |
|||
redisPool.getRedisTemplateByDb(14).opsForHash().put("wms_QyWxScanQrCodeSignature", "timestamp", String.valueOf(timestamp)); |
|||
redisPool.getRedisTemplateByDb(14).opsForHash().put("wms_QyWxScanQrCodeSignature", "url", url); |
|||
redisPool.getRedisTemplateByDb(14).opsForHash().put("wms_QyWxScanQrCodeSignature", "noncestr", noncestr); |
|||
|
|||
redisPool.getRedisTemplateByDb(14).expire("wms_QyWxScanQrCodeSignature", expires_in, TimeUnit.SECONDS); |
|||
|
|||
|
|||
} |
|||
result.put("timestamp", String.valueOf(timestamp)); |
|||
result.put("noncestr", noncestr); |
|||
result.put("jsapi_ticket_app", s); |
|||
result.put("jsapi_ticket_enterprises", s1); |
|||
result.put("corpid", QyWxConfig.corpid); |
|||
result.put("agentid", String.valueOf(QyWxConfig.AgentId)); |
|||
result.put("url", url); |
|||
|
|||
|
|||
return new RestResponse(result); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于接收企业微信审批的回调 |
|||
* |
|||
* @param map |
|||
* @param response |
|||
* @param request |
|||
*/ |
|||
@GetMapping("/approvalcallback") |
|||
public void approvalCallBackForGet(@RequestParam Map<String, Object> map, HttpServletResponse response, HttpServletRequest request) { |
|||
try { |
|||
// 构造解密对象
|
|||
WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(QyWxConfig.approvalToken, QyWxConfig.approvalEncodingAESKey, QyWxConfig.corpid); |
|||
// 企业微信加密签名
|
|||
String sVerifyMsgSig = (String) map.get("msg_signature"); |
|||
// 时间戳
|
|||
Integer sVerifyTimeStamp = ObjectFormatUtil.toInteger(map.get("timestamp")); |
|||
// 随机数
|
|||
String sVerifyNonce = (String) map.get("nonce"); |
|||
// 加密的字符串
|
|||
String sVerifyEchoStr = (String) map.get("echostr"); |
|||
String sEchoStr; //需要返回的明文
|
|||
sEchoStr = wxcpt.VerifyURL(sVerifyMsgSig, sVerifyTimeStamp.toString(), |
|||
sVerifyNonce, sVerifyEchoStr); |
|||
|
|||
// 添加日志
|
|||
CallBackLog callBackLog = new CallBackLog(); |
|||
callBackLog.setTimestamp(sVerifyTimeStamp); |
|||
callBackLog.setNonce(sVerifyNonce); |
|||
callBackLog.setEchostr(sVerifyEchoStr); |
|||
callBackLogService.addCallBackLog(callBackLog); |
|||
|
|||
//返回明文
|
|||
PrintWriter writer = response.getWriter(); |
|||
writer.println(sEchoStr); |
|||
|
|||
System.out.println(sEchoStr); |
|||
} catch (AesException | IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 用于接收企业微信的回调,post方式,审批相关 |
|||
*/ |
|||
@PostMapping("/approvalcallback") |
|||
public void approvalCallBackForPost(@RequestParam Map<String, Object> param, |
|||
@RequestBody(required = false) Map<String, Object> map, |
|||
HttpServletRequest request, HttpServletResponse response) { |
|||
try { |
|||
|
|||
|
|||
String header = request.getHeader("user-agent"); |
|||
String crypt = Md5.crypt(header); |
|||
// 构造解密对象
|
|||
WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(QyWxConfig.approvalToken, QyWxConfig.approvalEncodingAESKey, QyWxConfig.corpid); |
|||
// 企业微信加密签名
|
|||
String sVerifyMsgSig = (String) param.get("msg_signature"); |
|||
// 时间戳
|
|||
Integer sVerifyTimeStamp = ObjectFormatUtil.toInteger(param.get("timestamp")); |
|||
// 随机数
|
|||
String sVerifyNonce = (String) param.get("nonce"); |
|||
// 加密的字符串
|
|||
String sVerifyEchoStr = (String) param.get("echostr"); |
|||
|
|||
|
|||
if (sVerifyEchoStr != null) { |
|||
// 如果是验证url
|
|||
|
|||
String sEchoStr; //需要返回的明文
|
|||
sEchoStr = wxcpt.VerifyURL(sVerifyMsgSig, sVerifyTimeStamp.toString(), |
|||
sVerifyNonce, sVerifyEchoStr); |
|||
|
|||
// 添加日志
|
|||
CallBackLog callBackLog = new CallBackLog(); |
|||
callBackLog.setTimestamp(sVerifyTimeStamp); |
|||
callBackLog.setNonce(sVerifyNonce); |
|||
callBackLog.setEchostr(sVerifyEchoStr); |
|||
callBackLogService.addCallBackLog(callBackLog); |
|||
|
|||
//返回明文
|
|||
PrintWriter writer = response.getWriter(); |
|||
writer.println(sEchoStr); |
|||
writer.close(); |
|||
} |
|||
else { |
|||
String ToUserName = (String) map.get("ToUserName"); |
|||
String Encrypt = (String) map.get("Encrypt"); |
|||
String AgentID = (String) map.get("AgentID"); |
|||
|
|||
// 需要解密的xml
|
|||
String sReqData = String.format("<xml><ToUserName><![CDATA[%s]]></ToUserName>" + |
|||
"<Encrypt><![CDATA[%s]]></Encrypt>" + |
|||
"<AgentID><![CDATA[%s]]></AgentID></xml>", ToUserName, Encrypt, AgentID); |
|||
// 解析后的数据
|
|||
String sMsg = wxcpt.DecryptMsg(sVerifyMsgSig, sVerifyTimeStamp.toString(), sVerifyNonce, sReqData); |
|||
// 将xml转为对应对象
|
|||
ApprovalCallBackInfo approvalCallBackInfo = (ApprovalCallBackInfo) QyWxXMLUtils.convertXmlStrToObject(ApprovalCallBackInfo.class, sMsg); |
|||
// 具体信息
|
|||
ApprovalInfo approvalInfo = approvalCallBackInfo.getApprovalInfo(); |
|||
|
|||
// 获取当前审批的编号
|
|||
String spNo = approvalInfo.getSpNo(); |
|||
|
|||
// 获取当前审批关联的主订单
|
|||
String mainId = (String) redisPool.getRedisTemplateByDb(14).opsForHash().get("wms_QyWxMessage_" + spNo, "mainId"); |
|||
|
|||
// 获取所有审批流程信息
|
|||
List<ApprovalInfo_SpRecord> spRecord_list = approvalInfo.getSpRecord(); |
|||
|
|||
// 获取审批流程信息
|
|||
ApprovalInfo_SpRecord as = null; |
|||
// 获取审批节点详情
|
|||
ApprovalInfo_Details approvalInfo_details = null; |
|||
// 定义当前流程审批时间
|
|||
String as_SpTime = ""; |
|||
// 定义当前审批流程是是否要通过仓储中心
|
|||
boolean flagForFirst = true; // 默认通过
|
|||
|
|||
// 设置当前审批是否为仓库管理员(1为部门负责人,2为仓储中心,3为仓库管理员)
|
|||
int flagForDepository = 1; // 默认为部门负责人
|
|||
// 定义当前审批人的企业微信uid列表
|
|||
List<String> approverQyWxUid = new ArrayList<>(); |
|||
|
|||
// 定义已完成审批的节点数
|
|||
int approval_complete_count = 0; |
|||
// 定义当前审批流程的节点总数
|
|||
int approval_count = spRecord_list.size(); |
|||
|
|||
// 获取审批申请状态变化类型:1-提单;2-同意;3-驳回;4-转审;5-催办;6-撤销;8-通过后撤销;10-添加备注
|
|||
String spStatus = approvalInfo.getStatuChangeEvent(); |
|||
|
|||
for (ApprovalInfo_SpRecord approvalInfo_SpRecord : spRecord_list) { |
|||
|
|||
// 获取当前审批节点详情。当节点为标签或上级时,一个节点可能有多个分支
|
|||
List<ApprovalInfo_Details> details = approvalInfo_SpRecord.getDetails(); |
|||
|
|||
// 定义审批操作时间
|
|||
String spTime = ""; |
|||
// 定义审批操作状态
|
|||
String ad_SpStatus = ""; |
|||
// 定义审批详情
|
|||
ApprovalInfo_Details ap_detail = null; |
|||
|
|||
for (ApprovalInfo_Details ad : details) { |
|||
|
|||
// 获取节点分支审批人审批操作时间,0为尚未操作
|
|||
spTime = ad.getSpTime(); |
|||
|
|||
// 如果当前审批节点已经处理
|
|||
if (!("0".equals(spTime))) { |
|||
// 添加当前审批节点人的uid
|
|||
approverQyWxUid.add(ad.getApprover().getUserId()); |
|||
|
|||
// 设置当前处理的详情
|
|||
ap_detail = ad; |
|||
// 设置当前审批的状态
|
|||
ad_SpStatus = ad.getSpStatus(); |
|||
// 已审批节点数+1
|
|||
approval_complete_count++; |
|||
break; |
|||
} |
|||
} |
|||
if (!"0".equals(spTime)) { |
|||
// 如果已经操作
|
|||
|
|||
// 盘点当前审批状态是否为回调时操作状态
|
|||
if (ad_SpStatus.equals(spStatus)) { |
|||
// 将当前审批进行暂存
|
|||
if (as == null) { |
|||
// 如果是当前并没有获取到审批节点
|
|||
as = approvalInfo_SpRecord; |
|||
as_SpTime = spTime; |
|||
approvalInfo_details = ap_detail; |
|||
} else { |
|||
// 如果已经获取到审批节点
|
|||
|
|||
// 获取当前审批节点处理时间
|
|||
long aLong = ObjectFormatUtil.toLong(spTime); |
|||
|
|||
// 获取之前节点的审批时间
|
|||
long aLong1 = ObjectFormatUtil.toLong(as_SpTime); |
|||
|
|||
if (aLong >= aLong1) { |
|||
// 如果当前审批节点是最近处理
|
|||
|
|||
// 更新当前审批节点
|
|||
as = approvalInfo_SpRecord; |
|||
as_SpTime = spTime; |
|||
approvalInfo_details = ap_detail; |
|||
flagForFirst = false; |
|||
} |
|||
} |
|||
} |
|||
|
|||
} |
|||
} |
|||
|
|||
// 1-审批中;2-已同意;3-已驳回;4-已转审
|
|||
if (!("1".equals(spStatus))) { |
|||
|
|||
// 如果当前审批已同意
|
|||
if (QyWxConfig.out_approval_template_id.equals(approvalInfo.getTemplateId())) { |
|||
// 如果是物料出库申请审批
|
|||
|
|||
// 获取第二个节点数据
|
|||
ApprovalInfo_SpRecord approvalInfo_spRecord = null; |
|||
if (spRecord_list.size() > 1 && spRecord_list.size() < 4) { |
|||
// 如果审批节点数大于1小于等于4
|
|||
approvalInfo_spRecord = spRecord_list.get(1); |
|||
} |
|||
if (approvalInfo_spRecord != null) { |
|||
// 获取第二个节点中审批人信息
|
|||
List<ApprovalInfo_Details> details = approvalInfo_spRecord.getDetails(); |
|||
// 定义当前是否为标签
|
|||
boolean flagForLabel = true; // 默认为标签
|
|||
|
|||
// 获取当前的主订单
|
|||
ApplicationOutRecordP applicationOutRecordPById = depositoryRecordService.findApplicationOutRecordPById(ObjectFormatUtil.toLong(mainId)); |
|||
if(applicationOutRecordPById == null){ |
|||
return; |
|||
} |
|||
|
|||
if (Integer.compare(applicationOutRecordPById.getFlagForOpenDepository(), 2) == 0) { |
|||
// 如果是申请的开放仓库
|
|||
|
|||
// 获取当时发送审批时其他部门负责人Id
|
|||
String otherDepartmentIdList = (String) redisPool.getRedisTemplateByDb(14).opsForHash().get("wms_QyWxMessage_" + spNo, "otherDepartmentIdList"); |
|||
if (otherDepartmentIdList != null) { |
|||
for (ApprovalInfo_Details ad : details |
|||
) { |
|||
// 获取当前节点审批人userId
|
|||
String approver = ad.getApprover().getUserId(); |
|||
flagForLabel = flagForLabel && otherDepartmentIdList.contains(approver); |
|||
} |
|||
} |
|||
} else { |
|||
flagForLabel = false; |
|||
} |
|||
|
|||
|
|||
if (!flagForLabel && approval_count < 3) { |
|||
// 如果第二个节点不是标签节点且总节点数小于3个
|
|||
|
|||
if (approval_complete_count > 1) { |
|||
// 如果完成审批的节点数大于1
|
|||
flagForDepository = 3; |
|||
|
|||
// 如果已经完成该审批记录,则进行删除
|
|||
redisPool.getRedisTemplateByDb(14).delete("wms_QyWxMessage_" + spNo); |
|||
} else { |
|||
// 如果当前是第一个节点
|
|||
flagForFirst = false; |
|||
} |
|||
|
|||
} else { |
|||
// 如果第二个节点是标签节点
|
|||
if (approval_complete_count > 2) { |
|||
// 如果完成审批的节点数大于2
|
|||
flagForDepository = 3; |
|||
// 如果已经完成该审批记录,则进行删除
|
|||
redisPool.getRedisTemplateByDb(14).delete("wms_QyWxMessage_" + spNo); |
|||
} else { |
|||
// 如果当前并不是标签节点后
|
|||
flagForDepository = 2; |
|||
} |
|||
|
|||
} |
|||
} else { |
|||
// 如果为空则代表是中心仓下的办公用品库
|
|||
|
|||
int size = approverQyWxUid.size(); |
|||
if (size == 1) { |
|||
// 如果当前审批节点为第一个即部门负责人
|
|||
flagForFirst = true; |
|||
flagForDepository = 11; |
|||
} else if (size == 2) { |
|||
// 如果当前审批节点为第二个即平衡岗
|
|||
flagForFirst = true; |
|||
flagForDepository = 12; |
|||
} else if (size == 3) { |
|||
// 如果当前审批节点为综合办负责人
|
|||
flagForFirst = false; |
|||
flagForDepository = 2; |
|||
} else { |
|||
// 如果不是有操作的审批节点
|
|||
flagForDepository = 3; |
|||
} |
|||
} |
|||
|
|||
// 开启一个线程用于进行处理
|
|||
ApprovalInfo_Details finalApprovalInfo_details = approvalInfo_details; |
|||
boolean finalFlagForFirst = flagForFirst; |
|||
int finalFlagForDepository = flagForDepository; |
|||
HandlesOtherFunctionalThreadPool.execute(() -> depositoryRecordService.reviewByQyWxApprovalOut(mainId, finalApprovalInfo_details, crypt, spStatus, approvalInfo.getSpNo(), finalFlagForFirst, finalFlagForDepository)); |
|||
} else if (QyWxConfig.stockTaking_approval_template_id.equals(approvalInfo.getTemplateId())) { |
|||
// 如果是库存盘点审批
|
|||
// 开启一个线程用于进行处理
|
|||
ApprovalInfo_Details finalApprovalInfo_details = approvalInfo_details; |
|||
HandlesOtherFunctionalThreadPool.execute(() -> stockTakingService.reviewByQyWxApproval(mainId, finalApprovalInfo_details, crypt, spStatus, approvalInfo.getSpNo())); |
|||
} else if (QyWxConfig.in_approval_template_id.equals(approvalInfo.getTemplateId())) { |
|||
// 如果是入库审批
|
|||
// 开启一个线程用于进行处理
|
|||
ApprovalInfo_Details finalApprovalInfo_details = approvalInfo_details; |
|||
HandlesOtherFunctionalThreadPool.execute(() -> depositoryRecordService.reviewByQyWxApprovalIn(mainId, finalApprovalInfo_details, crypt, spStatus, spNo)); |
|||
} |
|||
// 开启一个线程用于进行下步操作
|
|||
} |
|||
|
|||
} |
|||
} catch (AesException | IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,181 @@ |
|||
package com.dreamchaser.depository_manage.controller; |
|||
|
|||
|
|||
import com.dreamchaser.depository_manage.entity.Inventory; |
|||
import com.dreamchaser.depository_manage.entity.SplitInfo; |
|||
import com.dreamchaser.depository_manage.entity.SplitInventory; |
|||
import com.dreamchaser.depository_manage.exception.MyException; |
|||
import com.dreamchaser.depository_manage.pojo.RestResponse; |
|||
import com.dreamchaser.depository_manage.pojo.StatusInfo; |
|||
import com.dreamchaser.depository_manage.service.MaterialService; |
|||
import com.dreamchaser.depository_manage.service.SplitUnitService; |
|||
import com.dreamchaser.depository_manage.utils.CrudUtil; |
|||
import com.dreamchaser.depository_manage.utils.ObjectFormatUtil; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Controller; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import javax.annotation.Resource; |
|||
import javax.servlet.http.HttpServletRequest; |
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
@RestController |
|||
@RequestMapping("/split") |
|||
public class SplitController { |
|||
|
|||
@Autowired |
|||
SplitUnitService splitUnitService; |
|||
|
|||
@Autowired |
|||
MaterialService materialService; |
|||
|
|||
|
|||
/** |
|||
* 用于添加一条拆单记录 |
|||
* |
|||
* @param map 待添加数据 |
|||
* @param request |
|||
* @return |
|||
*/ |
|||
@PostMapping("/splitAdd") |
|||
public RestResponse splitAdd(@RequestBody Map<String, Object> map, HttpServletRequest request) { |
|||
if (map.containsKey("quantity") && map.containsKey("newUnit")) { |
|||
return CrudUtil.insertHandle(1, splitUnitService.addSplitInfo(map)); |
|||
} else { |
|||
throw new MyException("缺少必要参数"); |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于查找当前库存的拆单记录 |
|||
* @param map |
|||
* @return |
|||
*/ |
|||
@PostMapping("/findSplitInventoryByIid") |
|||
public RestResponse findSplitInventoryByIid(@RequestBody Map<String, Object> map){ |
|||
if (map.containsKey("iid") ) { |
|||
Long iid = ObjectFormatUtil.toLong(map.get("iid")); |
|||
List<SplitInventory> splitInventoryByIid = splitUnitService.findSplitInventoryByIid(iid); |
|||
return new RestResponse(splitInventoryByIid); |
|||
} else { |
|||
throw new MyException("缺少必要参数"); |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于根据条件查询拆单记录 |
|||
* |
|||
* @param map 待查询条件 |
|||
* @param request |
|||
* @return |
|||
*/ |
|||
@GetMapping("/split_out") |
|||
public RestResponse splitOut(@RequestParam Map<String, Object> map, HttpServletRequest request) { |
|||
return new RestResponse(splitUnitService.findSplitInfoPByCondition(map), splitUnitService.findSplitInfoPCountByCondition(map), 200); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 根据条件删除对应的拆单记录 |
|||
* |
|||
* @param map 待删除数据 |
|||
* @return |
|||
*/ |
|||
@PostMapping("/split_del") |
|||
public RestResponse splitDel(@RequestBody Map<String, Object> map) { |
|||
if (map.containsKey("id")) { |
|||
Long id = ObjectFormatUtil.toLong(map.get("id")); |
|||
Integer integer = splitUnitService.delSplitInfoById(id); |
|||
if (Integer.compare(integer, -1) == 0) { |
|||
// 如果没有删除
|
|||
return new RestResponse("", 666, new StatusInfo("删除失败", "该拆单正在使用中,不允许进行删除操作")); |
|||
} else { |
|||
return CrudUtil.deleteHandle(1, integer); |
|||
} |
|||
} else if (map.containsKey("ids")) { |
|||
List<Long> ids = ObjectFormatUtil.objToList(map.get("ids"),Long.class); |
|||
List<SplitInfo> errInfo = new ArrayList<>(); |
|||
int result = 0; |
|||
for (Long id : ids) { |
|||
Integer integer = splitUnitService.delSplitInfoById(id); |
|||
if (Integer.compare(integer, -1) == 0) { |
|||
// 如果没有删除
|
|||
errInfo.add(splitUnitService.findSplitInfoById(id)); |
|||
} else { |
|||
result += integer; |
|||
} |
|||
} |
|||
if (result == ids.size()) { |
|||
return CrudUtil.deleteHandle(result, ids.size()); |
|||
} else { |
|||
return new RestResponse(errInfo, 666, new StatusInfo("删除失败", "有正在使用中的拆单,不允许进行删除")); |
|||
} |
|||
|
|||
} else { |
|||
throw new MyException("缺少必要参数"); |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 根据条件修改拆单信息 |
|||
* |
|||
* @param map 待修改数据 |
|||
* @return |
|||
*/ |
|||
@PostMapping("/split_edit") |
|||
public RestResponse splitEdit(@RequestBody Map<String, Object> map) { |
|||
if (map.containsKey("id")) { |
|||
Integer integer = splitUnitService.updateSplitInfo(map); |
|||
return CrudUtil.updateHandle(1, integer); |
|||
} else { |
|||
throw new MyException("缺少必要参数"); |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于查找当前禁用的拆单是否正在使用 |
|||
* |
|||
* @param map |
|||
* @return |
|||
*/ |
|||
@PostMapping("/findAllSplitInfoForbidden") |
|||
public RestResponse findAllSplitInfoForbidden(@RequestBody Map<String, Object> map) { |
|||
if (map.containsKey("id")) { |
|||
// 获取当前要禁用的拆单
|
|||
Long sid = ObjectFormatUtil.toLong(map.get("id")); |
|||
// 判断当前拆单是否可以禁用
|
|||
boolean sonSplitInfoByParentId = findSonSplitInfoByParentId(sid, true); |
|||
return new RestResponse(sonSplitInfoByParentId); |
|||
|
|||
} else { |
|||
throw new MyException("缺少必要参数"); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 获取当前拆单的子拆单 |
|||
* @param parentId 待查询父级id |
|||
* @param flag 标志位 |
|||
* @return |
|||
*/ |
|||
boolean findSonSplitInfoByParentId(Long parentId,boolean flag){ |
|||
// 获取当前的子拆单
|
|||
SplitInfo splitInfoByParentId = splitUnitService.findSplitInfoByParentId(parentId); |
|||
boolean allSplitInfoForbidden = splitUnitService.findAllSplitInfoForbidden(parentId); |
|||
if(splitInfoByParentId == null){ |
|||
// 如果不存在
|
|||
return allSplitInfoForbidden; |
|||
}else{ |
|||
// 如果存在
|
|||
|
|||
// 获取当前拆单是否可以禁用
|
|||
return findSonSplitInfoByParentId(splitInfoByParentId.getId(),flag && allSplitInfoForbidden); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,503 @@ |
|||
package com.dreamchaser.depository_manage.controller; |
|||
|
|||
|
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.dreamchaser.depository_manage.entity.MaterialAndPlace; |
|||
import com.dreamchaser.depository_manage.entity.Place; |
|||
import com.dreamchaser.depository_manage.entity.UserByPort; |
|||
import com.dreamchaser.depository_manage.pojo.RestResponse; |
|||
import com.dreamchaser.depository_manage.pojo.SimpleStockTakingP; |
|||
import com.dreamchaser.depository_manage.pojo.StatusInfo; |
|||
import com.dreamchaser.depository_manage.security.pool.AuthenticationTokenPool; |
|||
import com.dreamchaser.depository_manage.security.pool.RedisPool; |
|||
import com.dreamchaser.depository_manage.security.pool.SendQyWxMessageThreadPool; |
|||
import com.dreamchaser.depository_manage.service.*; |
|||
import com.dreamchaser.depository_manage.service.impl.QyWxOperationService; |
|||
import com.dreamchaser.depository_manage.utils.CrudUtil; |
|||
import com.dreamchaser.depository_manage.utils.DateUtil; |
|||
import com.dreamchaser.depository_manage.utils.Md5; |
|||
import com.dreamchaser.depository_manage.utils.ObjectFormatUtil; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import java.util.*; |
|||
import java.util.concurrent.TimeUnit; |
|||
|
|||
/** |
|||
* 库存盘点控制器 |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("/stockTaking") |
|||
public class StockTakingController { |
|||
@Autowired |
|||
MaterialService materialService; |
|||
|
|||
@Autowired |
|||
MaterialTypeService materialTypeService; |
|||
|
|||
@Autowired |
|||
StockTakingService stockTakingService; |
|||
|
|||
@Autowired |
|||
PlaceService placeService; |
|||
|
|||
@Autowired |
|||
QyWxOperationService qyWxOperationService; |
|||
|
|||
@Autowired |
|||
private RedisPool redisPool; |
|||
|
|||
@Autowired |
|||
private UserService userService; |
|||
|
|||
// 用于添加盘点记录
|
|||
@PostMapping("/addStockTakingRecord") |
|||
public RestResponse addStockTakingRecord(@RequestBody Map<String, Object> map, HttpServletRequest request) { |
|||
|
|||
String token = request.getHeader("user-token"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
|
|||
String header = request.getHeader("user-agent"); |
|||
String crypt = Md5.crypt(header); |
|||
|
|||
|
|||
List params = (ArrayList) map.get("params"); |
|||
String departmentManagerId = (String) map.get("departmentManagerId"); |
|||
map.put("departmentManager", departmentManagerId); |
|||
map.put("temp", 0); |
|||
// 用于设置企业微信接收人
|
|||
StringBuilder QyWxDepartmentManager = new StringBuilder(); |
|||
String[] split = departmentManagerId.split(","); |
|||
for (String s : split) { |
|||
if ("".equals(s)) { |
|||
continue; |
|||
} |
|||
UserByPort departmentManager = userService.findUserByNumberForNoPack(s); |
|||
int emptype = departmentManager.getEmptype(); |
|||
if (emptype > 10) { |
|||
continue; |
|||
} |
|||
String workwechat = departmentManager.getWorkwechat(); |
|||
if (workwechat == null || "".equals(workwechat)) { |
|||
workwechat = departmentManager.getWechat(); |
|||
} |
|||
QyWxDepartmentManager.append(workwechat+","); |
|||
} |
|||
//QyWxDepartmentManager.append("LiWenXuan").append(",");
|
|||
map.put("state", 3); |
|||
map.put("departmentManagerState", 3); |
|||
map.remove("departmentManagerId"); |
|||
map.put("originator", userToken.getId()); |
|||
String mcode = (String) map.get("code"); |
|||
map.remove("code"); |
|||
Integer success = 0; |
|||
if (params.size() > 0) { |
|||
// 如果有多个表
|
|||
Map<String, Object> param = new HashMap<>(); |
|||
param.put("depositoryId", map.get("depositoryId")); |
|||
param.put("placeId", map.get("placeId")); |
|||
param.put("departmentManager", map.get("departmentManager")); |
|||
param.put("state", 3); |
|||
param.put("departmentManagerState", 3); |
|||
param.put("originator", userToken.getId()); |
|||
for (Object o : params) { |
|||
Integer temp = ObjectFormatUtil.toInteger(o); |
|||
map.remove("code"); |
|||
param.put("mid", map.get("mid" + temp)); |
|||
param.put("barCode", map.get("barCode" + temp)); |
|||
param.put("oldInventory", map.get("oldInventory" + temp)); |
|||
param.put("newInventory", map.get("newInventory" + temp)); |
|||
param.put("takingResult", map.get("takingResult" + temp)); |
|||
param.put("inventory", map.get("inventory" + temp)); |
|||
param.put("producedDate", map.get("producedDate" + temp)); |
|||
param.put("unit", map.get("unit" + temp)); |
|||
param.put("temp", temp); |
|||
success += stockTakingService.insertStockTaking(param); |
|||
param.remove("id"); |
|||
} |
|||
param.put("temp", map.get("temp")); |
|||
param.put("mid", map.get("mid")); |
|||
param.put("barCode", map.get("barCode")); |
|||
param.put("oldInventory", map.get("oldInventory")); |
|||
param.put("newInventory", map.get("newInventory")); |
|||
param.put("takingResult", map.get("takingResult")); |
|||
param.put("inventory", map.get("inventory")); |
|||
param.put("producedDate", map.get("producedDate")); |
|||
param.put("unit", map.get("unit")); |
|||
success += stockTakingService.insertStockTaking(param); |
|||
|
|||
Object mainId = param.get("mainId"); |
|||
|
|||
// 用于发送审批
|
|||
SendQyWxMessageThreadPool.execute(() -> { |
|||
JSONObject jsonObject = qyWxOperationService.sendApprovalTemplateStockTaking(crypt, userToken, ObjectFormatUtil.toLong(mainId), QyWxDepartmentManager.toString()); |
|||
String sp_no = jsonObject.getString("sp_no"); |
|||
Map<String, Object> QyWxApprovalMap = new HashMap<>(); |
|||
QyWxApprovalMap.put("sp_no", sp_no); |
|||
QyWxApprovalMap.put("mainId", mainId.toString()); |
|||
redisPool.getRedisTemplateByDb(14).opsForHash().putAll("wms_QyWxMessage_" + sp_no, QyWxApprovalMap); |
|||
// 设置过期时间为7天
|
|||
redisPool.getRedisTemplateByDb(14).expire("wms_QyWxMessage_" + sp_no, 7, TimeUnit.DAYS); |
|||
}); |
|||
|
|||
} else { |
|||
// 如果只有一个表
|
|||
success += stockTakingService.insertStockTaking(map); |
|||
Object mainId = map.get("mainId"); |
|||
// 向企业微信发送消息
|
|||
|
|||
// 用于发送审批
|
|||
SendQyWxMessageThreadPool.execute(() -> { |
|||
JSONObject jsonObject = qyWxOperationService.sendApprovalTemplateStockTaking(crypt, userToken, ObjectFormatUtil.toLong(mainId), QyWxDepartmentManager.toString()); |
|||
String sp_no = jsonObject.getString("sp_no"); |
|||
Map<String, Object> QyWxApprovalMap = new HashMap<>(); |
|||
QyWxApprovalMap.put("sp_no", sp_no); |
|||
QyWxApprovalMap.put("mainId", mainId.toString()); |
|||
redisPool.getRedisTemplateByDb(14).opsForHash().putAll("wms_QyWxMessage_" + sp_no, QyWxApprovalMap); |
|||
// 设置过期时间为7天
|
|||
redisPool.getRedisTemplateByDb(14).expire("wms_QyWxMessage_" + sp_no, 7, TimeUnit.DAYS); |
|||
}); |
|||
|
|||
} |
|||
|
|||
if (params.size() > 0) { |
|||
return CrudUtil.insertHandle(success, params.size() + 1); |
|||
} else { |
|||
return CrudUtil.insertHandle(success, 1); |
|||
} |
|||
} |
|||
|
|||
|
|||
// 用于查询需要用户审核的盘点
|
|||
@GetMapping("/myTask") |
|||
public RestResponse myTask(@RequestParam Map<String, Object> map, HttpServletRequest request) { |
|||
String token = request.getHeader("user-token"); |
|||
String userKey = request.getHeader("user-key"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
userKey = (String) request.getSession().getAttribute("userKey"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
map.put("departmentHead", userToken.getNumber()); |
|||
List<SimpleStockTakingP> myTask = stockTakingService.findMyTask(map, userKey, token); |
|||
return new RestResponse(myTask, stockTakingService.findMyTaskCount(map), 200); |
|||
} |
|||
|
|||
// 用于审核
|
|||
@PostMapping("/review") |
|||
public RestResponse review(@RequestBody Map<String, Object> map, HttpServletRequest request) { |
|||
System.out.println("吧吧吧啵啵啵啵啵啵啵啵啵啵啵啵啵啵啵"); |
|||
String header = request.getHeader("user-agent"); |
|||
String crypt = Md5.crypt(header); |
|||
String token = request.getHeader("user-token"); |
|||
String userKey = request.getHeader("user-key"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
userKey = (String) request.getSession().getAttribute("userKey"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
Map<String, Object> review = stockTakingService.review(map, userToken, crypt, userKey, token); |
|||
|
|||
if (review.containsKey("errMsg")) { |
|||
// 如果有出错情况
|
|||
return new RestResponse(review, 666, new StatusInfo("有错误", "发现错误")); |
|||
} else { |
|||
return CrudUtil.insertHandle(1, 1); |
|||
} |
|||
} |
|||
|
|||
|
|||
// 用于完成订单
|
|||
@PostMapping("/complete") |
|||
public RestResponse complete(@RequestBody Map<String, Object> map, HttpServletRequest request) { |
|||
String token = request.getHeader("user-token"); |
|||
String userKey = request.getHeader("user-key"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
userKey = (String) request.getSession().getAttribute("userKey"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
String header = request.getHeader("user-agent"); |
|||
String crypt = Md5.crypt(header); |
|||
Map<String, Object> complete = stockTakingService.completeStockTaking(map, userToken, crypt, userKey, token); |
|||
if (complete.containsKey("errMsg")) { |
|||
// 如果有出错情况
|
|||
return new RestResponse(complete, 666, new StatusInfo("有错误", "发现错误")); |
|||
} else { |
|||
return CrudUtil.insertHandle(1, 1); |
|||
} |
|||
} |
|||
|
|||
// 用于查询用户提交的盘点
|
|||
@GetMapping("/myApply") |
|||
public RestResponse myApply(@RequestParam Map<String, Object> map, HttpServletRequest request) { |
|||
String token = request.getHeader("user-token"); |
|||
String userKey = request.getHeader("user-key"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
userKey = (String) request.getSession().getAttribute("userKey"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
map.put("userId", userToken.getId()); |
|||
List<SimpleStockTakingP> myApply = stockTakingService.findMyApply(map, userKey, token); |
|||
return new RestResponse(myApply, stockTakingService.findMyApplyCount(map), 200); |
|||
} |
|||
|
|||
|
|||
// 用于查询转入位置的容量
|
|||
@PostMapping("/findInventoryByLocation") |
|||
public RestResponse findInventoryByLocation(@RequestBody Map<String, Object> map, HttpServletRequest request) { |
|||
String token = request.getHeader("user-token"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
} |
|||
String placeId = (String) map.get("placeId"); |
|||
// 获取当前库位
|
|||
Place placeById = placeService.findPlaceById(ObjectFormatUtil.toLong(placeId)); |
|||
// 获取当前库位的容量
|
|||
Long inventory = placeById.getMax() - placeById.getQuantity(); |
|||
return new RestResponse(inventory); |
|||
} |
|||
|
|||
|
|||
// 用于进行盘点库存转移
|
|||
@PostMapping("/stockTransfer") |
|||
public RestResponse stockTransfer(@RequestBody Map<String, Object> map, HttpServletRequest request) { |
|||
|
|||
String token = request.getHeader("user-token"); |
|||
String userKey = request.getHeader("user-key"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
userKey = (String) request.getSession().getAttribute("userKey"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
String header = request.getHeader("user-agent"); |
|||
String crypt = Md5.crypt(header); |
|||
String minIds = (String) map.get("minIds"); |
|||
String[] split = minIds.split(","); |
|||
List<Integer> minIdList = new ArrayList<>(); |
|||
for (String s : split) { |
|||
if ("".equals(s)) { |
|||
continue; |
|||
} |
|||
minIdList.add(ObjectFormatUtil.toInteger(s)); |
|||
|
|||
} |
|||
map.put("minIds", minIdList); |
|||
|
|||
Integer transfer = stockTakingService.stockTakingTransfer(map, userToken, crypt, userKey, token); |
|||
return CrudUtil.insertHandle(transfer, minIdList.size()); |
|||
} |
|||
|
|||
/** |
|||
* 用于暂存当前盘点记录 |
|||
* |
|||
* @param map 存储数据 |
|||
* @param request |
|||
*/ |
|||
@PostMapping("/temporaryStorageForTakingResult") |
|||
public void temporaryStorageForTakingResult(@RequestBody Map<String, Object> map, HttpServletRequest request) { |
|||
// 获取当前盘点人
|
|||
String token = request.getHeader("user-token"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
// 获取当前暂存的结果id
|
|||
String key = "wms_stockTaking_" + userToken.getId() + "_" + DateUtil.getNowTime() + "_" + map.get("id"); |
|||
map.put("flagForSubmit", "false"); |
|||
redisPool.getRedisTemplateByDb(15).opsForHash().putAll(key, map); |
|||
// 存储到今天的12点
|
|||
redisPool.getRedisTemplateByDb(15).expire(key, DateUtil.getSecondsNextEarlyMorning(), TimeUnit.SECONDS); |
|||
|
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于删除暂存盘点记录 |
|||
* |
|||
* @param map 删除数据 |
|||
* @param request |
|||
*/ |
|||
@PostMapping("/delTemporaryStorageForTakingResult") |
|||
public RestResponse delTemporaryStorageForTakingResult(@RequestBody Map<String, Object> map, HttpServletRequest request) { |
|||
// 获取当前盘点人
|
|||
String token = request.getHeader("user-token"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
String key = "wms_stockTaking_" + userToken.getId() + "_" + DateUtil.getNowTime() + "_" + map.get("id"); |
|||
redisPool.getRedisTemplateByDb(15).delete(key); |
|||
return new RestResponse(); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 获取当前用户当前库存的盘点记录 |
|||
* |
|||
* @param map |
|||
* @param request |
|||
* @return |
|||
*/ |
|||
@PostMapping("/getTemporaryStorageForTakingResult") |
|||
public RestResponse getTemporaryStorageForTakingResult(@RequestBody Map<String, String> map, HttpServletRequest request) { |
|||
String token = request.getHeader("user-token"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
MaterialAndPlace mpv = placeService.findPlaceAndMaterialById(ObjectFormatUtil.toLong(map.get("mpId"))); |
|||
String key = "wms_stockTaking_" + userToken.getId() + "_" + DateUtil.getNowTime() + "_" + mpv.getId(); |
|||
// 设置结果集
|
|||
// 获取存储在redis中盘点记录的key
|
|||
Map<Object, Object> entries = redisPool.getRedisTemplateByDb(15).opsForHash().entries(key); |
|||
if (entries.size() > 0) { |
|||
return new RestResponse(entries); |
|||
} else { |
|||
return new RestResponse(null); |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 用于提交申请 |
|||
* |
|||
* @param map 提交的数据 |
|||
* @param request |
|||
* @return |
|||
*/ |
|||
@PostMapping("/submitStockTaking") |
|||
public RestResponse submitStockTaking(@RequestBody Map<String, Object> map, HttpServletRequest request) { |
|||
String token = request.getHeader("user-token"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
|
|||
String header = request.getHeader("user-agent"); |
|||
String crypt = Md5.crypt(header); |
|||
// 获取所有有关当前key的键
|
|||
String keyPatten = "wms_stockTaking_" + userToken.getId() + "_" + DateUtil.getNowTime() + "*"; |
|||
Set<String> keys = redisPool.getRedisTemplateByDb(15).keys(keyPatten); |
|||
int success = 0; |
|||
int size = 0; |
|||
if (keys != null && keys.size() > 0) { |
|||
Object mainId = null; |
|||
|
|||
size = keys.size(); |
|||
// 定义用于插入的盘点记录
|
|||
Map<String, Object> param = new HashMap<>(); |
|||
// 如果是指定位置
|
|||
if (map.containsKey("depositoryId")) { |
|||
// 如果存在
|
|||
for (String key : keys) { |
|||
Boolean flagForSubmit = ObjectFormatUtil.toBoolean(redisPool.getRedisTemplateByDb(15).opsForHash().get(key, "flagForSubmit")); |
|||
if (flagForSubmit != null && !flagForSubmit) { |
|||
// 如果是第一次提交
|
|||
|
|||
// 获取盘点时的物料与库位的对应关系id
|
|||
Long id = ObjectFormatUtil.toLong(redisPool.getRedisTemplateByDb(15).opsForHash().get(key, "id")); |
|||
// 获取物料与库位的对应关系
|
|||
MaterialAndPlace placeAndMaterial = placeService.findPlaceAndMaterialById(id); |
|||
|
|||
Object unit = redisPool.getRedisTemplateByDb(15).opsForHash().get(key, "unit"); |
|||
String takingResult = (String) redisPool.getRedisTemplateByDb(15).opsForHash().get(key, "takingResult"); |
|||
Object number = redisPool.getRedisTemplateByDb(15).opsForHash().get(key, "number"); |
|||
Object oldInventory = redisPool.getRedisTemplateByDb(15).opsForHash().get(key, "oldInventory"); |
|||
Integer newInventory = ObjectFormatUtil.toInteger(oldInventory); |
|||
if ("Inventory_down".equals(takingResult)) { |
|||
// 如果盘亏
|
|||
newInventory -= ObjectFormatUtil.toInteger(number); |
|||
|
|||
} else if ("Inventory_up".equals(takingResult)) { |
|||
// 如果盘盈
|
|||
newInventory += ObjectFormatUtil.toInteger(number); |
|||
} |
|||
param.put("newInventory", newInventory); |
|||
param.put("depositoryId", map.get("depositoryId")); |
|||
param.put("placeId", placeAndMaterial.getPid().toString()); |
|||
param.put("departmentManager", map.get("departmentManager")); |
|||
param.put("state", 3); |
|||
param.put("departmentManagerState", 3); |
|||
param.put("originator", userToken.getId()); |
|||
|
|||
param.put("mid", placeAndMaterial.getMid()); |
|||
param.put("oldInventory", oldInventory); |
|||
|
|||
param.put("takingResult", takingResult); |
|||
param.put("inventory", number); |
|||
param.put("unit", unit); |
|||
success += stockTakingService.insertStockTaking(param); |
|||
param.remove("id"); |
|||
|
|||
} |
|||
mainId = param.get("mainId"); |
|||
redisPool.getRedisTemplateByDb(15).opsForHash().put(key, "flagForSubmit", "true"); |
|||
} |
|||
} else { |
|||
// 如果是非指定位置
|
|||
success = stockTakingService.insertStockTakingByMaterial(map, keys, userToken); |
|||
|
|||
} |
|||
|
|||
// 用于设置企业微信接收人
|
|||
String departmentManagerId = (String) map.get("departmentManager"); |
|||
StringBuilder QyWxDepartmentManager = new StringBuilder(); |
|||
String[] split = departmentManagerId.split(","); |
|||
for (String s : split) { |
|||
if ("".equals(s)) { |
|||
continue; |
|||
} |
|||
UserByPort departmentManager = userService.findUserByNumberForNoPack(s); |
|||
int emptype = departmentManager.getEmptype(); |
|||
if (emptype > 10) { |
|||
continue; |
|||
} |
|||
String workwechat = departmentManager.getWorkwechat(); |
|||
if (workwechat == null || "".equals(workwechat)) { |
|||
workwechat = departmentManager.getWechat(); |
|||
} |
|||
QyWxDepartmentManager.append(workwechat+","); |
|||
} |
|||
//QyWxDepartmentManager.append("LiWenXuan");
|
|||
if (map.containsKey("mainIdList")) { |
|||
List<Object> mainIdList = ObjectFormatUtil.objToList(map.get("mainIdList"),Object.class); |
|||
for (Object main : mainIdList |
|||
) { |
|||
SendQyWxMessageThreadPool.execute(() -> { |
|||
JSONObject jsonObject = qyWxOperationService.sendApprovalTemplateStockTaking(crypt, userToken, ObjectFormatUtil.toLong(main), QyWxDepartmentManager.toString()); |
|||
String sp_no = jsonObject.getString("sp_no"); |
|||
Map<String, Object> QyWxApprovalMap = new HashMap<>(); |
|||
QyWxApprovalMap.put("sp_no", sp_no); |
|||
QyWxApprovalMap.put("mainId", main.toString()); |
|||
redisPool.getRedisTemplateByDb(14).opsForHash().putAll("wms_QyWxMessage_" + sp_no, QyWxApprovalMap); |
|||
// 设置过期时间为7天
|
|||
redisPool.getRedisTemplateByDb(14).expire("wms_QyWxMessage_" + sp_no, 7, TimeUnit.DAYS); |
|||
}); |
|||
} |
|||
} else { |
|||
// 用于发送审批
|
|||
Object finalMainId = mainId; |
|||
SendQyWxMessageThreadPool.execute(() -> { |
|||
JSONObject jsonObject = qyWxOperationService.sendApprovalTemplateStockTaking(crypt, userToken, ObjectFormatUtil.toLong(finalMainId), QyWxDepartmentManager.toString()); |
|||
String sp_no = jsonObject.getString("sp_no"); |
|||
Map<String, Object> QyWxApprovalMap = new HashMap<>(); |
|||
QyWxApprovalMap.put("sp_no", sp_no); |
|||
QyWxApprovalMap.put("mainId", finalMainId.toString()); |
|||
redisPool.getRedisTemplateByDb(14).opsForHash().putAll("wms_QyWxMessage_" + sp_no, QyWxApprovalMap); |
|||
// 设置过期时间为7天
|
|||
redisPool.getRedisTemplateByDb(14).expire("wms_QyWxMessage_" + sp_no, 7, TimeUnit.DAYS); |
|||
}); |
|||
} |
|||
|
|||
|
|||
} |
|||
|
|||
return CrudUtil.updateHandle(success, size); |
|||
} |
|||
} |
|||
@ -0,0 +1,536 @@ |
|||
package com.dreamchaser.depository_manage.controller; |
|||
|
|||
import com.alibaba.fastjson.JSONArray; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.dreamchaser.depository_manage.config.PublicConfig; |
|||
import com.dreamchaser.depository_manage.entity.AccesstoAddress; |
|||
import com.dreamchaser.depository_manage.entity.Depository; |
|||
import com.dreamchaser.depository_manage.entity.UserByPort; |
|||
import com.dreamchaser.depository_manage.exception.MyException; |
|||
import com.dreamchaser.depository_manage.pojo.*; |
|||
import com.dreamchaser.depository_manage.security.pool.AuthenticationTokenPool; |
|||
import com.dreamchaser.depository_manage.security.pool.RedisPool; |
|||
import com.dreamchaser.depository_manage.service.AccessAddressService; |
|||
import com.dreamchaser.depository_manage.service.DepositoryService; |
|||
import com.dreamchaser.depository_manage.service.RoleService; |
|||
import com.dreamchaser.depository_manage.utils.*; |
|||
import org.apache.http.protocol.HTTP; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import javax.servlet.http.HttpServletResponse; |
|||
import javax.servlet.http.HttpSession; |
|||
import java.io.IOException; |
|||
import java.time.Instant; |
|||
import java.util.*; |
|||
|
|||
import static com.dreamchaser.depository_manage.utils.CrudUtil.deleteHandle; |
|||
|
|||
|
|||
/** |
|||
* 用户的相关接口 |
|||
* |
|||
* @author 金昊霖 |
|||
*/ |
|||
@RestController |
|||
public class UserController { |
|||
|
|||
@Autowired |
|||
private RoleService roleService; |
|||
|
|||
@Autowired |
|||
private DepositoryService depositoryService; |
|||
|
|||
@Autowired |
|||
private RedisPool redisPool; |
|||
|
|||
|
|||
@Autowired |
|||
private AccessAddressService accessAddressService; |
|||
|
|||
|
|||
/** |
|||
* 登录接口 |
|||
* |
|||
* @param map 登录信息 |
|||
* restResponse,附带凭证token |
|||
*/ |
|||
@PostMapping("/login") |
|||
public RestResponse login(@RequestBody Map<String, String> map, HttpServletRequest request, HttpServletResponse response) { |
|||
response.setHeader("Access-Control-Allow-Origin", "*"); |
|||
String userWxId = map.get("userWxId"); |
|||
// 用于标识当前登录是否为企业微信跳转登录
|
|||
boolean flag = true; |
|||
if (!"".equals(userWxId)) { |
|||
// 如果是企业微信跳转
|
|||
flag = false; |
|||
} |
|||
JSONObject data = PublicConfig.baseLogin(map); |
|||
String userkey = (String) data.get("key"); |
|||
if (userkey != null) { |
|||
String userToken = (String) data.get("token"); |
|||
UserByPort userinfo = JSONObject.toJavaObject((JSONObject) data.get("usercont"), UserByPort.class); |
|||
|
|||
|
|||
// 设置放入时间
|
|||
userinfo.setInstant(Instant.now()); |
|||
// 将登录用户存储到池中保存
|
|||
AuthenticationTokenPool.addUserToken(userToken, userinfo); |
|||
|
|||
// 将key与token设置到session中
|
|||
request.getSession().setAttribute("userKey", userkey); |
|||
request.getSession().setAttribute("userToken", userToken); |
|||
request.getSession().setMaxInactiveInterval(3 * 60 * 60); |
|||
|
|||
if (!flag) { |
|||
// 如果是企业微信跳转
|
|||
Map<String, String> param = new HashMap<>(); |
|||
param.put("id", userinfo.getId().toString()); |
|||
param.put("workwechatid", userWxId); |
|||
// 将openid写回
|
|||
PublicConfig.editUserWechatOpenid(param, userkey, userToken); |
|||
} |
|||
|
|||
return new RestResponse(data); |
|||
} else { |
|||
return CrudUtil.NOT_EXIST_USER_OR_ERROR_PWD_RESPONSE; |
|||
} |
|||
|
|||
} |
|||
|
|||
|
|||
@GetMapping("/loginOut") |
|||
public RestResponse loginOut(HttpServletRequest request) { |
|||
HttpSession session = request.getSession(); |
|||
String token = request.getHeader("user-token"); |
|||
String key = request.getHeader("user-key"); |
|||
if (token != null) { |
|||
AuthenticationTokenPool.removeUserToken(token); |
|||
redisPool.getRedisTemplateByDb(5).delete(PublicConfig.LoginRedisPrefix + key); |
|||
} else { |
|||
String userKey = (String) session.getAttribute("userKey"); |
|||
String userToken = (String) session.getAttribute("userToken"); |
|||
AuthenticationTokenPool.removeUserToken(userToken); |
|||
//liwenxuan 20230804 本地环境登出时不删redis, 上线要改回来 测试用
|
|||
redisPool.getRedisTemplateByDb(5).delete(PublicConfig.LoginRedisPrefix + userKey); |
|||
} |
|||
session.invalidate(); |
|||
return new RestResponse("", 200, new StatusInfo("退出成功", "退出成功")); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 获取人员列表 |
|||
* |
|||
* @param map |
|||
* @return |
|||
*/ |
|||
@PostMapping("/sys/findUsers") |
|||
public RestResponse findUsersByPort(@RequestParam Map<String, Object> map, HttpServletRequest request) { |
|||
String token = request.getHeader("user-token"); |
|||
String userkey = request.getHeader("user-key"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
userkey = (String) request.getSession().getAttribute("userKey"); |
|||
} |
|||
String url = PublicConfig.external_url + "/staff/archiveslist"; |
|||
if (map.containsKey("company")) { |
|||
map.put("company", ObjectFormatUtil.toInteger(map.get("company"))); |
|||
} |
|||
if (map.containsKey("adminorg")) { |
|||
map.put("adminorg", ObjectFormatUtil.toInteger(map.get("adminorg"))); |
|||
} |
|||
Object page = map.get("page"); |
|||
Object pagesize = map.get("size"); |
|||
map.put("page", ObjectFormatUtil.toInteger(page)); |
|||
map.put("pagesize", ObjectFormatUtil.toInteger(pagesize)); |
|||
String jsonString = JSONObject.toJSONString(map); |
|||
JSONObject paramObject = JSONObject.parseObject(jsonString); |
|||
String post = null; |
|||
try { |
|||
post = HttpUtils.send(url, paramObject, HTTP.UTF_8, userkey, token); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
JSONObject jsonObject = JSONObject.parseObject(post); |
|||
JSONObject data = (JSONObject) jsonObject.get("data"); |
|||
JSONArray list = (JSONArray) data.get("list"); |
|||
if (list == null) { |
|||
list = new JSONArray(); |
|||
} |
|||
Integer total = ObjectFormatUtil.toInteger(data.get("total")); |
|||
List<UserByPortP> userByPortList = new ArrayList<>(); |
|||
for (Object o : list) { |
|||
UserByPort userByPort = JSONObject.toJavaObject((JSONObject) o, UserByPort.class); |
|||
UserByPortP user = new UserByPortP(userByPort); |
|||
Map<String, Object> param = new HashMap<>(); |
|||
param.put("userId", userByPort.getId()); |
|||
param.put("classes", 1); |
|||
List<RoleAndDepository> roleAndDepositoryByCondition = roleService.findRoleAndDepositoryByCondition(param); |
|||
RoleAndDepository depositoryAndRole = null; |
|||
if (roleAndDepositoryByCondition.size() > 0) { |
|||
depositoryAndRole = roleAndDepositoryByCondition.get(0); |
|||
} |
|||
if (depositoryAndRole != null && depositoryAndRole.getClasses() != 2) { |
|||
user.setDepositoryName(depositoryAndRole.getDepositoryName()); |
|||
} else { |
|||
user.setDepositoryName(""); |
|||
} |
|||
userByPortList.add(user); |
|||
} |
|||
return new RestResponse(userByPortList, total, 200); |
|||
} |
|||
|
|||
|
|||
// 通过名称获取人员
|
|||
@PostMapping("/sys/findUserByName") |
|||
public RestResponse findUserByName(@RequestBody Map<String, String> map, HttpServletRequest request) { |
|||
Map<String, Object> paramForUser = new HashMap<>(); |
|||
paramForUser.put("name", map.get("name")); |
|||
String token = request.getHeader("user-token"); |
|||
String userkey = request.getHeader("user-key"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
userkey = (String) request.getSession().getAttribute("userKey"); |
|||
} |
|||
// 获取当前获取用户时查询范围
|
|||
String scope = map.get("scope"); |
|||
if ("department".equals(scope)) { |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
// 如果是部门级别
|
|||
paramForUser.put("adminorg", userToken.getMaindeparment()); |
|||
} |
|||
List<UserByPort> userByPortList = PublicConfig.FindUserByMap(paramForUser, userkey, token); |
|||
List<UserByPortP> userByPortP = new ArrayList<>(); |
|||
for (UserByPort userByPort : userByPortList) { |
|||
// 获取当前用户的用工关系
|
|||
int emptype = userByPort.getEmptype(); |
|||
if (emptype <= 10) { |
|||
// 如果是在职人员
|
|||
userByPortP.add(new UserByPortP(userByPort)); |
|||
} |
|||
} |
|||
return new RestResponse(userByPortP, userByPortP.size(), 200); |
|||
|
|||
} |
|||
|
|||
|
|||
/** |
|||
* 添加用户管理仓库的权限 |
|||
* |
|||
* @param map |
|||
* @return |
|||
*/ |
|||
@PostMapping("/sys/user_role") |
|||
public RestResponse addUser(@RequestBody Map<String, Object> map) { |
|||
Map<String, Object> param = new HashMap<>(); |
|||
param.put("userId", map.get("userid")); |
|||
param.put("classes", map.get("classes")); |
|||
if (map.containsKey("depositoryId")) { |
|||
param.put("depositoryId", map.get("depositoryId")); |
|||
List<RoleAndDepository> roleAndDepositoryByCondition = roleService.findRoleAndDepositoryByCondition(param); |
|||
if (roleAndDepositoryByCondition.size() > 0) { |
|||
return CrudUtil.insertHandle(-1, -1); |
|||
} else { |
|||
Integer integer = roleService.addUserOrPostRoleAndDepository(map); |
|||
return CrudUtil.insertHandle(integer, integer); |
|||
} |
|||
} else { |
|||
List<Depository> depositoryAll = depositoryService.findDepositoryAll(); |
|||
Integer success = 0; |
|||
for (Depository depository : depositoryAll) { |
|||
param.put("depositoryId", depository.getId()); |
|||
map.put("depositoryId", depository.getId()); |
|||
List<RoleAndDepository> roleAndDepositoryByCondition = roleService.findRoleAndDepositoryByCondition(param); |
|||
if (roleAndDepositoryByCondition.size() <= 0) { |
|||
success += roleService.addUserOrPostRoleAndDepository(map); |
|||
} |
|||
} |
|||
return CrudUtil.insertHandle(success, depositoryAll.size()); |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 添加用户管理仓库的权限 |
|||
* |
|||
* @param map |
|||
* @return |
|||
*/ |
|||
@PostMapping("/sys/user_roleForIn") |
|||
public RestResponse addUserForIn(@RequestBody Map<String, Object> map) { |
|||
Map<String, Object> param = new HashMap<>(); |
|||
param.put("uid", map.get("userid")); |
|||
param.put("classes", map.get("classes")); |
|||
param.put("mtid", map.get("mtid")); |
|||
List<RoleAndMaterialType> roleAndMaterialTypeByCondition = roleService.findRoleAndMaterialTypeByCondition(param); |
|||
if (roleAndMaterialTypeByCondition.size() > 0) { |
|||
return CrudUtil.insertHandle(-1, -1); |
|||
} else { |
|||
Integer integer = roleService.addUserOrPostRoleAndMaterialType(map); |
|||
return CrudUtil.insertHandle(integer, integer); |
|||
} |
|||
} |
|||
|
|||
|
|||
@PostMapping("/sys/userRole_editForIn") |
|||
public RestResponse editUserRoleForIn(@RequestBody Map<String, Object> map) { |
|||
return CrudUtil.insertHandle(roleService.UpdateRoleAndMaterialTypeById(map), 1); |
|||
} |
|||
|
|||
|
|||
|
|||
/** |
|||
* 根据主键删除管理仓库权限 |
|||
* |
|||
* @param map |
|||
* @return |
|||
*/ |
|||
@PostMapping("/sys/userRole_del") |
|||
public RestResponse deleteRoleAndDepository(@RequestBody Map<String, Object> map) { |
|||
if (map.containsKey("id")) { |
|||
Long id = ObjectFormatUtil.toLong(map.get("id")); |
|||
return CrudUtil.deleteHandle(roleService.deleteRoleAndDepositoryById(id), 1); |
|||
} else if (map.containsKey("ids")) { |
|||
Integer num = 0; |
|||
List<Long> ids = ObjectFormatUtil.objToList(map.get("ids"),Long.class); |
|||
for (Long id : ids) { |
|||
num += roleService.deleteRoleAndDepositoryById(id); |
|||
} |
|||
return CrudUtil.deleteHandle(num, ids.size()); |
|||
} else { |
|||
throw new MyException("所需请求参数缺失!"); |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 根据主键删除管理类型权限 |
|||
* |
|||
* @param map |
|||
* @return |
|||
*/ |
|||
@PostMapping("/sys/userRole_delForIn") |
|||
public RestResponse deleteRoleAndMaterialType(@RequestBody Map<String, Object> map) { |
|||
if (map.containsKey("id")) { |
|||
Long id = ObjectFormatUtil.toLong(map.get("id")); |
|||
return CrudUtil.deleteHandle(roleService.deleteRoleAndMaterialTypeById(id), 1); |
|||
} else if (map.containsKey("ids")) { |
|||
Integer num = 0; |
|||
List<Long> ids = ObjectFormatUtil.objToList(map.get("ids"),Long.class); |
|||
for (Long id : ids) { |
|||
num += roleService.deleteRoleAndMaterialTypeById(id); |
|||
} |
|||
return CrudUtil.deleteHandle(num, ids.size()); |
|||
} else { |
|||
throw new MyException("所需请求参数缺失!"); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 获取验证码 |
|||
* |
|||
* @return |
|||
*/ |
|||
@GetMapping("/getCaptchaid") |
|||
public JSONObject getCaptchaid(HttpServletRequest httpServletRequest, HttpServletResponse response) { |
|||
response.setHeader("Access-Control-Allow-Origin", "*"); |
|||
JSONObject captcha = PublicConfig.Captcha(httpServletRequest); |
|||
return captcha; |
|||
} |
|||
|
|||
|
|||
@PostMapping("/accountLook") |
|||
public RestResponse accountLook(HttpServletRequest request) { |
|||
String token = request.getHeader("user-token"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
return new RestResponse(userToken); |
|||
} |
|||
|
|||
@GetMapping("/findUserRole") |
|||
public RestResponse findUserRole(@RequestParam Map<String, Object> map, HttpServletRequest request) { |
|||
String token = request.getHeader("user-token"); |
|||
String userKey = request.getHeader("user-key"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
userKey = (String) request.getSession().getAttribute("userKey"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
List<UserByPortP> userByPortPList = new ArrayList<>(); |
|||
String classes = (String) map.get("classes"); |
|||
List<RoleAndDepository> roleAndDepositoryByCondition = roleService.findRoleAndDepositoryByCondition(map); |
|||
for (RoleAndDepository roleAndDepository : roleAndDepositoryByCondition) { |
|||
UserByPort userByPort = PublicConfig.FindUserById(roleAndDepository.getUserId(), userKey, token); |
|||
UserByPortP up = new UserByPortP(userByPort); |
|||
up.setId(roleAndDepository.getId()); |
|||
up.setDepositoryName(roleAndDepository.getDepositoryName()); |
|||
userByPortPList.add(up); |
|||
} |
|||
return new RestResponse(userByPortPList, roleService.findRoleAndDepositoryCountByCondition(map), 200); |
|||
} |
|||
|
|||
@GetMapping("/findUserInRole") |
|||
public RestResponse findUserInRole(@RequestParam Map<String, Object> map, HttpServletRequest request) { |
|||
String token = request.getHeader("user-token"); |
|||
String userKey = request.getHeader("user-key"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
userKey = (String) request.getSession().getAttribute("userKey"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
List<UserByPortP> userByPortPList = new ArrayList<>(); |
|||
// 如果查询的是入库
|
|||
List<RoleAndMaterialType> roleAndMaterialTypeByCondition = roleService.findRoleAndMaterialTypeByCondition(map); |
|||
for (RoleAndMaterialType roleAndMaterialType : roleAndMaterialTypeByCondition |
|||
) { |
|||
UserByPort userByPort = PublicConfig.FindUserById(roleAndMaterialType.getUid(), userKey, token); |
|||
UserByPortP up = new UserByPortP(userByPort); |
|||
up.setId(roleAndMaterialType.getId()); |
|||
up.setMaterialTypeName(roleAndMaterialType.getTname()); |
|||
userByPortPList.add(up); |
|||
} |
|||
return new RestResponse(userByPortPList, roleService.findRoleAndMaterialTypeCountByCondition(map), 200); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 获取所有菜单 |
|||
* |
|||
* @param |
|||
* @return |
|||
*/ |
|||
@RequestMapping(value = "/index/menus", method = RequestMethod.GET) |
|||
public Map<String, Object> index_menus(HttpServletRequest request, |
|||
HttpServletResponse response) { |
|||
String token = request.getHeader("user-token"); |
|||
String userKey = request.getHeader("user-key"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
userKey = (String) request.getSession().getAttribute("userKey"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
List<String> stringList = PublicConfig.getUserAccessToAddresses(userKey, token); |
|||
List<AccesstoAddress> accessToAddressByList = accessAddressService.findAccessToAddressByList(stringList); |
|||
// 获取顶级菜单
|
|||
List<AccesstoAddress> menusByNoParent = new ArrayList<>(); |
|||
for (AccesstoAddress value : accessToAddressByList) { |
|||
if (value.getMenuparent() == 0) { |
|||
menusByNoParent.add(value); |
|||
} |
|||
} |
|||
//定义首页
|
|||
|
|||
Map<String, Object> home = new HashMap<>(); |
|||
Map<String, Object> homeInfo = new HashMap<>(); |
|||
homeInfo.put("title", "首页"); |
|||
homeInfo.put("href", "/welcome"); |
|||
home.put("homeInfo", homeInfo); |
|||
|
|||
//定义logo
|
|||
Map<String, Object> logo = new HashMap<>(); |
|||
Map<String, Object> logoInfo = new HashMap<>(); |
|||
logoInfo.put("title", ""); |
|||
logoInfo.put("image", "/static/images/logo_back.ico"); |
|||
logoInfo.put("href", ""); |
|||
logo.put("logoInfo", logoInfo); |
|||
//定义菜单
|
|||
List<Object> allMenus = new ArrayList<>(); |
|||
for (AccesstoAddress menusparent : menusByNoParent) { |
|||
// 获取所有二级菜单
|
|||
Map<String, Object> menu = MenuConstructor(menusparent); |
|||
List<AccesstoAddress> accessstoAddressByParent = childAddress(accessToAddressByList, menusparent); |
|||
List<Object> menu_childs = new ArrayList<>(); |
|||
for (AccesstoAddress address : accessstoAddressByParent) { |
|||
// 二级菜单下的菜单
|
|||
Map<String, Object> menu_child = MenuConstructor(address); |
|||
List<Object> menu_childs1 = new ArrayList<>(); |
|||
if (address.getIschild() == 1) { |
|||
List<AccesstoAddress> accessstoAddressByParent1 = childAddress(accessToAddressByList, address); |
|||
for (AccesstoAddress accesstoAddress : accessstoAddressByParent1) { |
|||
Map<String, Object> menu_child1 = MenuConstructor(accesstoAddress); |
|||
menu_childs1.add(((HashMap<String, Object>) menu_child1).clone()); |
|||
menu_child1.clear(); |
|||
} |
|||
} |
|||
menu_child.put("child", ((ArrayList<Object>) menu_childs1).clone()); |
|||
menu_childs.add(((HashMap<String, Object>) menu_child).clone()); |
|||
menu_child.clear(); |
|||
} |
|||
menu.put("child", menu_childs); |
|||
allMenus.add(menu); |
|||
} |
|||
Map<String, Object> menuInfo = new HashMap<>(); |
|||
menuInfo.put("menuInfo", allMenus); |
|||
menuInfo.put("homeInfo", homeInfo); |
|||
menuInfo.put("logoInfo", logoInfo); |
|||
return menuInfo; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 根据父级菜单获取子菜单 |
|||
* |
|||
* @param accessToAddressByList |
|||
* @param address |
|||
* @return |
|||
*/ |
|||
public List<AccesstoAddress> childAddress(List<AccesstoAddress> accessToAddressByList, AccesstoAddress address) { |
|||
List<AccesstoAddress> accessstoAddressByParent = new ArrayList<>(); |
|||
for (AccesstoAddress accesstoAddress : accessToAddressByList) { |
|||
if (Long.compare(accesstoAddress.getMenuparent(), address.getId()) == 0) { |
|||
accessstoAddressByParent.add(accesstoAddress); |
|||
} |
|||
} |
|||
return accessstoAddressByParent; |
|||
} |
|||
|
|||
/** |
|||
* 用于菜单构造 |
|||
* |
|||
* @param address |
|||
* @return |
|||
*/ |
|||
public Map<String, Object> MenuConstructor(AccesstoAddress address) { |
|||
Map<String, Object> menu = new HashMap<>(); |
|||
menu.put("title", address.getName()); |
|||
menu.put("href", address.getUrl()); |
|||
menu.put("icon", address.getIcon()); |
|||
menu.put("target", address.getTarget()); |
|||
return menu; |
|||
} |
|||
|
|||
/** |
|||
* 用于移动端用户获取其可见功能 |
|||
* |
|||
* @param request |
|||
* @return |
|||
*/ |
|||
@GetMapping("/getUserAuthorization") |
|||
public RestResponse getUserAuthorization(HttpServletRequest request) { |
|||
String token = request.getHeader("user-token"); |
|||
String userKey = request.getHeader("user-key"); |
|||
if (token == null) { |
|||
token = (String) request.getSession().getAttribute("userToken"); |
|||
userKey = (String) request.getSession().getAttribute("userKey"); |
|||
} |
|||
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|||
// 获取当前用户可见的菜单id
|
|||
List<String> stringList = PublicConfig.getUserAccessToAddresses(userKey, token); |
|||
// 根据菜单id获取菜单信息
|
|||
List<AccesstoAddress> accessToAddressByList = accessAddressService.findAccessToAddressByList(stringList); |
|||
List<AccesstoAddress> result = new ArrayList<>(); |
|||
for (AccesstoAddress ata : accessToAddressByList |
|||
) { |
|||
if (ata.getIschild() == 2) { |
|||
result.add(ata); |
|||
} |
|||
} |
|||
return new RestResponse(result); |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,114 @@ |
|||
package com.dreamchaser.depository_manage.controller; |
|||
|
|||
import com.dreamchaser.depository_manage.entity.UserByPort; |
|||
import com.dreamchaser.depository_manage.security.pool.AuthenticationTokenPool; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import javax.websocket.*; |
|||
import javax.websocket.server.PathParam; |
|||
import javax.websocket.server.ServerEndpoint; |
|||
import java.io.IOException; |
|||
import java.util.concurrent.ConcurrentHashMap; |
|||
import java.util.concurrent.CopyOnWriteArraySet; |
|||
|
|||
@Component |
|||
// 主要是将目前的类定义成一个websocket服务器端
|
|||
@ServerEndpoint("/webSocket/{number}") // 接收路径
|
|||
|
|||
@Slf4j |
|||
public class WebSocketController { |
|||
//concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。
|
|||
//虽然@Component默认是单例模式的,但springboot还是会为每个websocket连接初始化一个bean,所以可以用一个静态set保存起来
|
|||
// 。
|
|||
// 注:底下WebSocket是当前类名
|
|||
private static CopyOnWriteArraySet<WebSocketController> webSockets = new CopyOnWriteArraySet<>(); |
|||
// 用来存在线连接用户信息
|
|||
private static ConcurrentHashMap<String, Session> sessionPool = new ConcurrentHashMap<String, Session>(); |
|||
//与某个客户端的连接会话,需要通过它来给客户端发送数据
|
|||
private Session session; |
|||
//接收sid
|
|||
private String number = ""; |
|||
|
|||
/** |
|||
* 群发自定义消息 |
|||
*/ |
|||
public static void sendInfo(String message, @PathParam("number") String number) throws IOException { |
|||
Session session = sessionPool.get(number); |
|||
if (session != null && session.isOpen()) { |
|||
log.info("推送消息到窗口" + number + ",推送内容:" + message); |
|||
for (WebSocketController item : webSockets) { |
|||
try { |
|||
|
|||
if (item.number.equals(number)) { |
|||
item.sendMessage(message); |
|||
} |
|||
} catch (IOException e) { |
|||
log.error(e.getMessage()); |
|||
} |
|||
} |
|||
} |
|||
|
|||
} |
|||
|
|||
/** |
|||
* 链接成功调用的方法 |
|||
*/ |
|||
@OnOpen |
|||
public void onOpen(Session session, @PathParam("number") String number) { |
|||
try { |
|||
this.session = session; |
|||
webSockets.add(this); |
|||
sessionPool.put(number, session); |
|||
this.number = number; |
|||
System.out.println("连接成功"); |
|||
log.info("【websocket消息】有新的连接,总数为:" + webSockets.size()); |
|||
} catch (Exception e) { |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 链接关闭调用的方法 |
|||
*/ |
|||
@OnClose |
|||
public void onClose() { |
|||
try { |
|||
sessionPool.remove(this.number); |
|||
webSockets.remove(this); |
|||
log.info("【websocket消息】连接断开,总数为:" + webSockets.size()); |
|||
} catch (Exception e) { |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 收到客户端消息后调用的方法 |
|||
* |
|||
* @param message |
|||
*/ |
|||
@OnMessage |
|||
public void onMessage(String message) { |
|||
log.info("【websocket消息】收到客户端消息:" + message); |
|||
} |
|||
|
|||
/** |
|||
* 发送错误时的处理 |
|||
* |
|||
* @param session |
|||
* @param error |
|||
*/ |
|||
@OnError |
|||
public void onError(Session session, Throwable error) { |
|||
log.error("用户错误,原因:" + error.getMessage()); |
|||
error.printStackTrace(); |
|||
} |
|||
|
|||
/** |
|||
* 实现服务器主动推送 |
|||
*/ |
|||
public void sendMessage(String message) throws IOException { |
|||
this.session.getBasicRemote().sendText(message); |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,66 @@ |
|||
package com.dreamchaser.depository_manage.converter; |
|||
|
|||
|
|||
import com.alibaba.excel.converters.Converter; |
|||
import com.alibaba.excel.enums.CellDataTypeEnum; |
|||
import com.alibaba.excel.metadata.GlobalConfiguration; |
|||
import com.alibaba.excel.metadata.data.ReadCellData; |
|||
import com.alibaba.excel.metadata.data.WriteCellData; |
|||
import com.alibaba.excel.metadata.property.ExcelContentProperty; |
|||
import com.dreamchaser.depository_manage.entity.Depository; |
|||
import com.dreamchaser.depository_manage.service.DepositoryService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import javax.annotation.PostConstruct; |
|||
|
|||
/** |
|||
* 用于将仓库编码转为仓库id |
|||
*/ |
|||
@Component |
|||
public class ExcelDepositoryInfoConverter implements Converter<Long> { |
|||
|
|||
private static ExcelDepositoryInfoConverter excelDepositoryInfoConverter; |
|||
@Autowired |
|||
private DepositoryService depositoryService; |
|||
|
|||
@Override |
|||
public Class supportJavaTypeKey() { |
|||
return Long.class; |
|||
} |
|||
|
|||
@Override |
|||
public CellDataTypeEnum supportExcelTypeKey() { |
|||
return CellDataTypeEnum.STRING; |
|||
} |
|||
|
|||
@Override |
|||
public Long convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception { |
|||
Long data = 0L; |
|||
Depository depository = excelDepositoryInfoConverter.depositoryService.findDepositoryByCode(cellData.getStringValue()); |
|||
if (depository != null) { |
|||
data = depository.getId(); |
|||
} |
|||
if (data == 0) { |
|||
throw new RuntimeException("没有该仓库"); |
|||
} |
|||
return data; |
|||
} |
|||
|
|||
@Override |
|||
public WriteCellData<String> convertToExcelData(Long value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception { |
|||
Depository depository = excelDepositoryInfoConverter.depositoryService.findDepositoryById(value); |
|||
String data = ""; |
|||
if(depository != null) { |
|||
data = depository.getCode(); |
|||
} |
|||
|
|||
return new WriteCellData<>(data); |
|||
} |
|||
|
|||
@PostConstruct |
|||
public void init() { |
|||
excelDepositoryInfoConverter = this; |
|||
excelDepositoryInfoConverter.depositoryService = this.depositoryService; |
|||
} |
|||
} |
|||
@ -0,0 +1,40 @@ |
|||
package com.dreamchaser.depository_manage.converter; |
|||
|
|||
import com.alibaba.excel.converters.Converter; |
|||
import com.alibaba.excel.enums.CellDataTypeEnum; |
|||
import com.alibaba.excel.metadata.GlobalConfiguration; |
|||
import com.alibaba.excel.metadata.data.ReadCellData; |
|||
import com.alibaba.excel.metadata.data.WriteCellData; |
|||
import com.alibaba.excel.metadata.property.ExcelContentProperty; |
|||
import com.dreamchaser.depository_manage.entity.MaterialType; |
|||
import com.dreamchaser.depository_manage.utils.ObjectFormatUtil; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 用于物料分类上级编码 |
|||
*/ |
|||
@Component |
|||
public class ExcelMTParentIdConverter implements Converter<Integer> { |
|||
@Override |
|||
public Class supportJavaTypeKey() { |
|||
return Integer.class; |
|||
} |
|||
|
|||
@Override |
|||
public CellDataTypeEnum supportExcelTypeKey() { |
|||
return CellDataTypeEnum.STRING; |
|||
} |
|||
|
|||
|
|||
@Override |
|||
public Integer convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception { |
|||
Integer data = 0; |
|||
if(cellData.getStringValue() != null){ |
|||
data = ObjectFormatUtil.toInteger(cellData.getStringValue()); |
|||
} |
|||
return data; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,59 @@ |
|||
package com.dreamchaser.depository_manage.converter; |
|||
|
|||
import com.alibaba.excel.converters.Converter; |
|||
import com.alibaba.excel.converters.ReadConverterContext; |
|||
import com.alibaba.excel.enums.CellDataTypeEnum; |
|||
import com.alibaba.excel.metadata.GlobalConfiguration; |
|||
import com.alibaba.excel.metadata.data.ReadCellData; |
|||
import com.alibaba.excel.metadata.property.ExcelContentProperty; |
|||
import com.dreamchaser.depository_manage.entity.Depository; |
|||
import com.dreamchaser.depository_manage.entity.Material; |
|||
import com.dreamchaser.depository_manage.service.DepositoryService; |
|||
import com.dreamchaser.depository_manage.service.MaterialService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import javax.annotation.PostConstruct; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 用于物料分类上级编码 |
|||
*/ |
|||
@Component |
|||
public class ExcelMaterialCodeConverter implements Converter<String> { |
|||
|
|||
@Autowired |
|||
private MaterialService materialService; |
|||
|
|||
private static ExcelMaterialCodeConverter excelMaterialCodeConverter; |
|||
@Override |
|||
public Class<?> supportJavaTypeKey() { |
|||
return String.class; |
|||
} |
|||
|
|||
@Override |
|||
public CellDataTypeEnum supportExcelTypeKey() { |
|||
return CellDataTypeEnum.STRING; |
|||
} |
|||
|
|||
/** |
|||
* 这里读的时候会调用 |
|||
* |
|||
* @param |
|||
* @return |
|||
*/ |
|||
@Override |
|||
public String convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception { |
|||
Material material = excelMaterialCodeConverter.materialService.findMaterialByCode(cellData.getStringValue()); |
|||
if(material == null) { |
|||
throw new RuntimeException("没有该物料"); |
|||
} |
|||
return (cellData.getStringValue()); |
|||
} |
|||
|
|||
@PostConstruct |
|||
public void init(){ |
|||
excelMaterialCodeConverter = this; |
|||
excelMaterialCodeConverter.materialService = this.materialService; |
|||
} |
|||
} |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue