parent
70dff2caa5
commit
93cf71adb0
@ -0,0 +1,74 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<annotationProcessing>
|
||||||
|
<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="demo" />
|
||||||
|
<module name="leyou-api-gateway" />
|
||||||
|
<module name="leyou-authentication-common" />
|
||||||
|
<module name="leyou-authentication-service" />
|
||||||
|
<module name="leyou-cart" />
|
||||||
|
<module name="leyou-comment-service" />
|
||||||
|
<module name="leyou-comments-interface" />
|
||||||
|
<module name="leyou-comments-service" />
|
||||||
|
<module name="leyou-common" />
|
||||||
|
<module name="leyou-config" />
|
||||||
|
<module name="leyou-goods-web" />
|
||||||
|
<module name="leyou-item-interface" />
|
||||||
|
<module name="leyou-item-service" />
|
||||||
|
<module name="leyou-mongondb" />
|
||||||
|
<module name="leyou-order-interface" />
|
||||||
|
<module name="leyou-order-service" />
|
||||||
|
<module name="leyou-registry" />
|
||||||
|
<module name="leyou-search" />
|
||||||
|
<module name="leyou-seckill-interface" />
|
||||||
|
<module name="leyou-seckill-service" />
|
||||||
|
<module name="leyou-sms" />
|
||||||
|
<module name="leyou-upload" />
|
||||||
|
<module name="leyou-user-interface" />
|
||||||
|
<module name="leyou-user-service" />
|
||||||
|
</profile>
|
||||||
|
</annotationProcessing>
|
||||||
|
<bytecodeTargetLevel>
|
||||||
|
<module name="demo" target="1.8" />
|
||||||
|
<module name="leyou-comment" target="1.8" />
|
||||||
|
<module name="leyou-comment-interface" target="1.8" />
|
||||||
|
<module name="leyou-comment-service" target="1.8" />
|
||||||
|
<module name="leyou-mongondb" target="1.8" />
|
||||||
|
<module name="leyou-review" target="1.8" />
|
||||||
|
<module name="leyou-review-interface" target="1.8" />
|
||||||
|
<module name="leyou-review-service" target="1.8" />
|
||||||
|
<module name="leyou-review-servie" target="1.8" />
|
||||||
|
<module name="leyou-test" target="1.8" />
|
||||||
|
<module name="leyout-test" target="1.8" />
|
||||||
|
</bytecodeTargetLevel>
|
||||||
|
</component>
|
||||||
|
<component name="JavacSettings">
|
||||||
|
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
|
||||||
|
<module name="leyou-api-gateway" options="-parameters" />
|
||||||
|
<module name="leyou-authentication-common" options="-parameters" />
|
||||||
|
<module name="leyou-authentication-service" options="-parameters" />
|
||||||
|
<module name="leyou-cart" options="-parameters" />
|
||||||
|
<module name="leyou-comments-interface" options="-parameters" />
|
||||||
|
<module name="leyou-comments-service" options="-parameters" />
|
||||||
|
<module name="leyou-common" options="-parameters" />
|
||||||
|
<module name="leyou-config" options="-parameters" />
|
||||||
|
<module name="leyou-goods-web" options="-parameters" />
|
||||||
|
<module name="leyou-item-interface" options="-parameters" />
|
||||||
|
<module name="leyou-item-service" options="-parameters" />
|
||||||
|
<module name="leyou-order-interface" options="-parameters" />
|
||||||
|
<module name="leyou-order-service" options="-parameters" />
|
||||||
|
<module name="leyou-registry" options="-parameters" />
|
||||||
|
<module name="leyou-search" options="-parameters" />
|
||||||
|
<module name="leyou-seckill-interface" options="-parameters" />
|
||||||
|
<module name="leyou-seckill-service" options="-parameters" />
|
||||||
|
<module name="leyou-sms" options="-parameters" />
|
||||||
|
<module name="leyou-upload" options="-parameters" />
|
||||||
|
<module name="leyou-user-interface" options="-parameters" />
|
||||||
|
<module name="leyou-user-service" options="-parameters" />
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,34 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding">
|
||||||
|
<file url="file://$PROJECT_DIR$" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/leyou-api-gateway" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/leyou-authentication" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/leyou-authentication/leyou-authentication-common" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/leyou-authentication/leyou-authentication-service" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/leyou-cart" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/leyou-comments" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/leyou-comments/leyou-comments-interface" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/leyou-comments/leyou-comments-service" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/leyou-common" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/leyou-config" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/leyou-goods-web" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/leyou-item" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/leyou-item/leyou-item-interface" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/leyou-item/leyou-item-service" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/leyou-order" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/leyou-order/leyou-order-interface" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/leyou-order/leyou-order-service" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/leyou-registry" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/leyou-search" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/leyou-secskill" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/leyou-secskill/leyou-seckill-interface" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/leyou-secskill/leyou-seckill-service" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/leyou-sms" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/leyou-upload" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/leyou-user" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/leyou-user/leyou-user-interface" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/leyou-user/leyou-user-service" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/leyout-test" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,43 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="ConstantConditions" enabled="false" level="WARNING" enabled_by_default="false">
|
||||||
|
<option name="SUGGEST_NULLABLE_ANNOTATIONS" value="false" />
|
||||||
|
<option name="DONT_REPORT_TRUE_ASSERT_STATEMENTS" value="false" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="JavaDoc" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="TOP_LEVEL_CLASS_OPTIONS">
|
||||||
|
<value>
|
||||||
|
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||||
|
<option name="REQUIRED_TAGS" value="" />
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
<option name="INNER_CLASS_OPTIONS">
|
||||||
|
<value>
|
||||||
|
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||||
|
<option name="REQUIRED_TAGS" value="" />
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
<option name="METHOD_OPTIONS">
|
||||||
|
<value>
|
||||||
|
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||||
|
<option name="REQUIRED_TAGS" value="@return@param@throws or @exception" />
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
<option name="FIELD_OPTIONS">
|
||||||
|
<value>
|
||||||
|
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||||
|
<option name="REQUIRED_TAGS" value="" />
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
<option name="IGNORE_DEPRECATED" value="false" />
|
||||||
|
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
|
||||||
|
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
|
||||||
|
<option name="IGNORE_POINT_TO_ITSELF" value="false" />
|
||||||
|
<option name="myAdditionalJavadocTags" value="date" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="MavenModelInspection" enabled="false" level="ERROR" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="SpringJavaInjectionPointsAutowiringInspection" enabled="false" level="ERROR" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="ThymeleafVariablesResolveInspection" enabled="false" level="ERROR" enabled_by_default="false" />
|
||||||
|
</profile>
|
||||||
|
</component>
|
@ -0,0 +1,56 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
|
<component name="FrameworkDetectionExcludesConfiguration">
|
||||||
|
<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" />
|
||||||
|
<option value="$PROJECT_DIR$/leyou-review/leyou-review-service/pom.xml" />
|
||||||
|
<option value="$PROJECT_DIR$/leyou-review/leyou-review-servie/pom.xml" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="NullableNotNullManager">
|
||||||
|
<option name="myDefaultNullable" value="org.jetbrains.annotations.Nullable" />
|
||||||
|
<option name="myDefaultNotNull" value="javax.validation.constraints.NotNull" />
|
||||||
|
<option name="myNullables">
|
||||||
|
<value>
|
||||||
|
<list size="9">
|
||||||
|
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
|
||||||
|
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
|
||||||
|
<item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
|
||||||
|
<item index="3" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
|
||||||
|
<item index="4" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
|
||||||
|
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.Nullable" />
|
||||||
|
<item index="6" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.Nullable" />
|
||||||
|
<item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableDecl" />
|
||||||
|
<item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableType" />
|
||||||
|
</list>
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
<option name="myNotNulls">
|
||||||
|
<value>
|
||||||
|
<list size="9">
|
||||||
|
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
|
||||||
|
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
|
||||||
|
<item index="2" class="java.lang.String" itemvalue="javax.validation.constraints.NotNull" />
|
||||||
|
<item index="3" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
|
||||||
|
<item index="4" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
|
||||||
|
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.NonNull" />
|
||||||
|
<item index="6" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.NonNull" />
|
||||||
|
<item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullDecl" />
|
||||||
|
<item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullType" />
|
||||||
|
</list>
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/leyou-comment/leyou-comment-service/leyou-comment-service.iml" filepath="$PROJECT_DIR$/leyou-comment/leyou-comment-service/leyou-comment-service.iml" />
|
||||||
|
</modules>
|
||||||
|
</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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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,201 @@
|
|||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
http://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.
|
@ -0,0 +1,25 @@
|
|||||||
|
package com.leyou;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Author: 98050
|
||||||
|
* Time: 2018-08-03 20:41
|
||||||
|
* Feature:
|
||||||
|
*/
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author li
|
||||||
|
* @time: 2018-08-03 20:41
|
||||||
|
*/
|
||||||
|
@SpringBootApplication
|
||||||
|
@EnableDiscoveryClient
|
||||||
|
@EnableZuulProxy
|
||||||
|
public class LyApiGateway {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(LyApiGateway.class,args);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
package com.leyou.config;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* @Time: 2018-10-24 16:55
|
||||||
|
* @Feature: 过滤白名单
|
||||||
|
*/
|
||||||
|
//@ConfigurationProperties(prefix = "leyou.filter")
|
||||||
|
@Configuration
|
||||||
|
@RefreshScope
|
||||||
|
public class FilterProperties {
|
||||||
|
|
||||||
|
@Value("${leyou.filter.allowPaths}")
|
||||||
|
private String allowPaths;
|
||||||
|
|
||||||
|
public String getAllowPaths() {
|
||||||
|
return allowPaths;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAllowPaths(String allowPaths) {
|
||||||
|
this.allowPaths = allowPaths;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,85 @@
|
|||||||
|
package com.leyou.config;
|
||||||
|
|
||||||
|
import com.leyou.auth.utils.RsaUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import java.io.File;
|
||||||
|
import java.security.PublicKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* @Time: 2018-10-24 16:12
|
||||||
|
* @Feature: jwt属性
|
||||||
|
*/
|
||||||
|
//@ConfigurationProperties(prefix = "leyou.jwt")
|
||||||
|
@Configuration
|
||||||
|
@RefreshScope
|
||||||
|
public class JwtProperties {
|
||||||
|
/**
|
||||||
|
* 公钥
|
||||||
|
*/
|
||||||
|
private PublicKey publicKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公钥地址
|
||||||
|
*/
|
||||||
|
@Value("${leyou.jwt.pubKeyPath}")
|
||||||
|
private String pubKeyPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cookie名字
|
||||||
|
*/
|
||||||
|
@Value("${leyou.jwt.cookieName}")
|
||||||
|
private String cookieName;
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(JwtProperties.class);
|
||||||
|
|
||||||
|
public PublicKey getPublicKey() {
|
||||||
|
return publicKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublicKey(PublicKey publicKey) {
|
||||||
|
this.publicKey = publicKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPubKeyPath() {
|
||||||
|
return pubKeyPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPubKeyPath(String pubKeyPath) {
|
||||||
|
this.pubKeyPath = pubKeyPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCookieName() {
|
||||||
|
return cookieName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCookieName(String cookieName) {
|
||||||
|
this.cookieName = cookieName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Logger getLogger() {
|
||||||
|
return logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @PostConstruct :在构造方法执行之后执行该方法
|
||||||
|
*/
|
||||||
|
@PostConstruct
|
||||||
|
public void init(){
|
||||||
|
try {
|
||||||
|
// 获取公钥
|
||||||
|
this.publicKey = RsaUtils.getPublicKey(pubKeyPath);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("获取公钥失败!", e);
|
||||||
|
throw new RuntimeException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
spring:
|
||||||
|
cloud:
|
||||||
|
config:
|
||||||
|
name: gateway
|
||||||
|
profile: dev
|
||||||
|
label: master
|
||||||
|
uri: http://127.0.0.1:10011
|
@ -0,0 +1,50 @@
|
|||||||
|
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>leyou-authentication</artifactId>
|
||||||
|
<groupId>com.leyou.authentication</groupId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.leyou.authentication</groupId>
|
||||||
|
<artifactId>leyou-authentication-common</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-lang3</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.jsonwebtoken</groupId>
|
||||||
|
<artifactId>jjwt</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>joda-time</groupId>
|
||||||
|
<artifactId>joda-time</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<mainClass>com.xx.webapps.api.main.WebappsApiBidMain</mainClass>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
@ -0,0 +1,35 @@
|
|||||||
|
package com.leyou.auth.entity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户信息
|
||||||
|
*/
|
||||||
|
public class UserInfo {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
public UserInfo() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserInfo(Long id, String username) {
|
||||||
|
this.id = id;
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsername(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
package com.leyou.auth.utils;
|
||||||
|
|
||||||
|
public abstract class JwtConstans {
|
||||||
|
public static final String JWT_KEY_ID = "id";
|
||||||
|
public static final String JWT_KEY_USER_NAME = "username";
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
package com.leyou.auth.utils;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
public class ObjectUtils {
|
||||||
|
|
||||||
|
public static String toString(Object obj) {
|
||||||
|
if (obj == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return obj.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Long toLong(Object obj) {
|
||||||
|
if (obj == null) {
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
if (obj instanceof Double || obj instanceof Float) {
|
||||||
|
return Long.valueOf(StringUtils.substringBefore(obj.toString(), "."));
|
||||||
|
}
|
||||||
|
if (obj instanceof Number) {
|
||||||
|
return Long.valueOf(obj.toString());
|
||||||
|
}
|
||||||
|
if (obj instanceof String) {
|
||||||
|
return Long.valueOf(obj.toString());
|
||||||
|
} else {
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Integer toInt(Object obj) {
|
||||||
|
return toLong(obj).intValue();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
package com.leyou.auth.test;
|
||||||
|
|
||||||
|
import com.leyou.auth.entity.UserInfo;
|
||||||
|
import com.leyou.auth.utils.JwtUtils;
|
||||||
|
import com.leyou.auth.utils.RsaUtils;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.security.PrivateKey;
|
||||||
|
import java.security.PublicKey;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* @Time: 2018-10-23 20:58
|
||||||
|
* @Feature: JWT测试
|
||||||
|
*/
|
||||||
|
public class JwtTest {
|
||||||
|
|
||||||
|
private static final String pubKeyPath = "G:\\tmp\\rsa\\rsa.pub";
|
||||||
|
|
||||||
|
private static final String priKeyPath = "G:\\tmp\\rsa\\rsa.pri";
|
||||||
|
|
||||||
|
private PublicKey publicKey;
|
||||||
|
|
||||||
|
private PrivateKey privateKey;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRsa() throws Exception {
|
||||||
|
RsaUtils.generateKey(pubKeyPath, priKeyPath, "234");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void testGetRsa() throws Exception {
|
||||||
|
this.publicKey = RsaUtils.getPublicKey(pubKeyPath);
|
||||||
|
this.privateKey = RsaUtils.getPrivateKey(priKeyPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGenerateToken() throws Exception {
|
||||||
|
// 生成token
|
||||||
|
String token = JwtUtils.generateToken(new UserInfo(20L, "jack"), privateKey, 5);
|
||||||
|
System.out.println("token = " + token);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParseToken() throws Exception {
|
||||||
|
String token = "eyJhbGciOiJSUzI1NiJ9.eyJpZCI6MjAsInVzZXJuYW1lIjoiamFjayIsImV4cCI6MTU0MDMwMjU4MX0.KFGDe8V8TwLl5xGqM1brPV50JXf3Z6G4cXPIeYxsqaeeol06BnXNNsyLAbUSrFxloUf-hQqO41O1OrtERllU-JfZXs6MA6rTBSfpar2MJRSZyDGKqfBpPoRED3yZv8oFuzI_94GONqsipmGyQFqWUkhTf9k0tZ5LPRvvGl9tkvc";
|
||||||
|
|
||||||
|
// 解析token
|
||||||
|
UserInfo user = JwtUtils.getInfoFromToken(token, publicKey);
|
||||||
|
System.out.println("id: " + user.getId());
|
||||||
|
System.out.println("userName: " + user.getUsername());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void date(){
|
||||||
|
System.out.println(new Date());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package com.leyou.auth;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* @Time: 2018-10-23 20:11
|
||||||
|
* @Feature: 授权服务启动器
|
||||||
|
*/
|
||||||
|
@SpringBootApplication
|
||||||
|
@EnableDiscoveryClient
|
||||||
|
@EnableFeignClients
|
||||||
|
public class LyAuthApplication {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(LyAuthApplication.class,args);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.leyou.auth.client;
|
||||||
|
|
||||||
|
import com.leyou.user.api.UserApi;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* @Time: 2018-10-23 23:48
|
||||||
|
* @Feature: 用户feignclient
|
||||||
|
*/
|
||||||
|
@FeignClient(value = "user-service")
|
||||||
|
public interface UserClient extends UserApi {
|
||||||
|
}
|
@ -0,0 +1,158 @@
|
|||||||
|
package com.leyou.auth.properties;
|
||||||
|
|
||||||
|
import com.leyou.auth.utils.RsaUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import java.io.File;
|
||||||
|
import java.security.PrivateKey;
|
||||||
|
import java.security.PublicKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* @Time: 2018-10-23 22:20
|
||||||
|
* @Feature: jwt配置参数
|
||||||
|
*/
|
||||||
|
//@ConfigurationProperties(prefix = "leyou.jwt")
|
||||||
|
@Configuration
|
||||||
|
@RefreshScope
|
||||||
|
public class JwtProperties {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密钥
|
||||||
|
*/
|
||||||
|
@Value("${leyou.jwt.secret}")
|
||||||
|
private String secret;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公钥地址
|
||||||
|
*/
|
||||||
|
@Value("${leyou.jwt.pubKeyPath}")
|
||||||
|
private String pubKeyPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 私钥地址
|
||||||
|
*/
|
||||||
|
@Value("${leyou.jwt.priKeyPath}")
|
||||||
|
private String priKeyPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* token过期时间
|
||||||
|
*/
|
||||||
|
@Value("${leyou.jwt.expire}")
|
||||||
|
private int expire;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公钥
|
||||||
|
*/
|
||||||
|
private PublicKey publicKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 私钥
|
||||||
|
*/
|
||||||
|
private PrivateKey privateKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cookie名字
|
||||||
|
*/
|
||||||
|
@Value("${leyou.jwt.cookieName}")
|
||||||
|
private String cookieName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cookie生命周期
|
||||||
|
*/
|
||||||
|
@Value("${leyou.jwt.cookieMaxAge}")
|
||||||
|
private Integer cookieMaxAge;
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(JwtProperties.class);
|
||||||
|
|
||||||
|
public String getSecret() {
|
||||||
|
return secret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSecret(String secret) {
|
||||||
|
this.secret = secret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPubKeyPath() {
|
||||||
|
return pubKeyPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPubKeyPath(String pubKeyPath) {
|
||||||
|
this.pubKeyPath = pubKeyPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPriKeyPath() {
|
||||||
|
return priKeyPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPriKeyPath(String priKeyPath) {
|
||||||
|
this.priKeyPath = priKeyPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getExpire() {
|
||||||
|
return expire;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExpire(int expire) {
|
||||||
|
this.expire = expire;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PublicKey getPublicKey() {
|
||||||
|
return publicKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublicKey(PublicKey publicKey) {
|
||||||
|
this.publicKey = publicKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PrivateKey getPrivateKey() {
|
||||||
|
return privateKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrivateKey(PrivateKey privateKey) {
|
||||||
|
this.privateKey = privateKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCookieName() {
|
||||||
|
return cookieName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCookieName(String cookieName) {
|
||||||
|
this.cookieName = cookieName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getCookieMaxAge() {
|
||||||
|
return cookieMaxAge;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCookieMaxAge(Integer cookieMaxAge) {
|
||||||
|
this.cookieMaxAge = cookieMaxAge;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @PostConstruct :在构造方法执行之后执行该方法
|
||||||
|
*/
|
||||||
|
@PostConstruct
|
||||||
|
public void init(){
|
||||||
|
try {
|
||||||
|
File pubKey = new File(pubKeyPath);
|
||||||
|
File priKey = new File(priKeyPath);
|
||||||
|
if (!pubKey.exists() || !priKey.exists()) {
|
||||||
|
// 生成公钥和私钥
|
||||||
|
RsaUtils.generateKey(pubKeyPath, priKeyPath, secret);
|
||||||
|
}
|
||||||
|
// 获取公钥和私钥
|
||||||
|
this.publicKey = RsaUtils.getPublicKey(pubKeyPath);
|
||||||
|
this.privateKey = RsaUtils.getPrivateKey(priKeyPath);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("初始化公钥和私钥失败!", e);
|
||||||
|
throw new RuntimeException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.leyou.auth.service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* @Time: 2018-10-23 22:46
|
||||||
|
* @Feature:
|
||||||
|
*/
|
||||||
|
public interface AuthService {
|
||||||
|
/**
|
||||||
|
* 用户授权
|
||||||
|
* @param username
|
||||||
|
* @param password
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
String authentication(String username, String password);
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
spring:
|
||||||
|
cloud:
|
||||||
|
config:
|
||||||
|
name: auth
|
||||||
|
profile: dev
|
||||||
|
label: master
|
||||||
|
uri: http://127.0.0.1:10011
|
@ -0,0 +1,21 @@
|
|||||||
|
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>leyou</artifactId>
|
||||||
|
<groupId>com.leyou.parent</groupId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.leyou.authentication</groupId>
|
||||||
|
<artifactId>leyou-authentication</artifactId>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<modules>
|
||||||
|
<module>leyou-authentication-common</module>
|
||||||
|
<module>leyou-authentication-service</module>
|
||||||
|
</modules>
|
||||||
|
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.leyou.cart;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* @Time: 2018-10-24 20:46
|
||||||
|
* @Feature:购物车启动器
|
||||||
|
*/
|
||||||
|
@SpringBootApplication
|
||||||
|
@EnableDiscoveryClient
|
||||||
|
@EnableFeignClients
|
||||||
|
public class LyCartApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(LyCartApplication.class,args);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.leyou.cart.client;
|
||||||
|
|
||||||
|
import com.leyou.item.api.GoodsApi;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* @Time: 2018-10-25 21:03
|
||||||
|
* @Feature: 商品FeignClient
|
||||||
|
*/
|
||||||
|
@FeignClient(value = "item-service")
|
||||||
|
public interface GoodsClient extends GoodsApi {
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
package com.leyou.cart.config;
|
||||||
|
|
||||||
|
import com.leyou.cart.interceptor.LoginInterceptor;
|
||||||
|
import com.leyou.cart.properties.JwtProperties;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* @Time: 2018-10-25 19:48
|
||||||
|
* @Feature: 配置过滤器
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
//@EnableConfigurationProperties(JwtProperties.class)
|
||||||
|
public class MvcConfig implements WebMvcConfigurer {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private JwtProperties jwtProperties;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public LoginInterceptor loginInterceptor(){
|
||||||
|
return new LoginInterceptor(jwtProperties);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addInterceptors(InterceptorRegistry registry) {
|
||||||
|
registry.addInterceptor(loginInterceptor()).addPathPatterns("/**");
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Bean
|
||||||
|
// public FilterRegistrationBean someFilterRegistration1() {
|
||||||
|
// //新建过滤器注册类
|
||||||
|
// FilterRegistrationBean registration = new FilterRegistrationBean();
|
||||||
|
// // 添加我们写好的过滤器
|
||||||
|
// registration.setFilter( new CartFilter());
|
||||||
|
// // 设置过滤器的URL模式
|
||||||
|
// registration.addUrlPatterns("/*");
|
||||||
|
// return registration;
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
package com.leyou.cart.controller;
|
||||||
|
|
||||||
|
import com.leyou.cart.pojo.Cart;
|
||||||
|
import com.leyou.cart.service.CartService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* @Time: 2018-10-25 20:41
|
||||||
|
* @Feature:
|
||||||
|
*/
|
||||||
|
@Controller
|
||||||
|
public class CartController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CartService cartService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加购物车
|
||||||
|
* @param cart
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping
|
||||||
|
public ResponseEntity<Void> addCart(@RequestBody Cart cart){
|
||||||
|
this.cartService.addCart(cart);
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询购物车
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping
|
||||||
|
public ResponseEntity<List<Cart>> queryCartList(){
|
||||||
|
List<Cart> carts = this.cartService.queryCartList();
|
||||||
|
if(carts == null){
|
||||||
|
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(carts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改购物车中商品数量
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PutMapping
|
||||||
|
public ResponseEntity<Void> updateNum(@RequestParam("skuId") Long skuId,@RequestParam("num") Integer num){
|
||||||
|
this.cartService.updateNum(skuId,num);
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除购物车中的商品
|
||||||
|
* @param skuId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@DeleteMapping("{skuId}")
|
||||||
|
public ResponseEntity<Void> deleteCart(@PathVariable("skuId") String skuId){
|
||||||
|
this.cartService.deleteCart(skuId);
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package com.leyou.cart.filter;
|
||||||
|
|
||||||
|
|
||||||
|
import javax.servlet.*;
|
||||||
|
import javax.servlet.annotation.WebFilter;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* @Time: 2018-10-25 20:00
|
||||||
|
* @Feature:
|
||||||
|
*/
|
||||||
|
//@WebFilter(filterName = "CartFilter",urlPatterns = {"/**"})
|
||||||
|
public class CartFilter implements Filter {
|
||||||
|
@Override
|
||||||
|
public void init(FilterConfig filterConfig) throws ServletException {
|
||||||
|
System.out.println("过滤器初始化");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
|
||||||
|
System.out.println("具体过滤规则");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroy() {
|
||||||
|
System.out.println("销毁");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,112 @@
|
|||||||
|
package com.leyou.cart.pojo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* @Time: 2018-10-25 20:27
|
||||||
|
* @Feature: 购物车实体类
|
||||||
|
*/
|
||||||
|
public class Cart {
|
||||||
|
/**
|
||||||
|
* 用户Id
|
||||||
|
*/
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品id
|
||||||
|
*/
|
||||||
|
private Long skuId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标题
|
||||||
|
*/
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图片
|
||||||
|
*/
|
||||||
|
private String image;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加入购物车时的价格
|
||||||
|
*/
|
||||||
|
private Long price;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 购买数量
|
||||||
|
*/
|
||||||
|
private Integer num;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品规格参数
|
||||||
|
*/
|
||||||
|
private String ownSpec;
|
||||||
|
|
||||||
|
public Long getUserId() {
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserId(Long userId) {
|
||||||
|
this.userId = userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getSkuId() {
|
||||||
|
return skuId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSkuId(Long skuId) {
|
||||||
|
this.skuId = skuId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getImage() {
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImage(String image) {
|
||||||
|
this.image = image;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getPrice() {
|
||||||
|
return price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrice(Long price) {
|
||||||
|
this.price = price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getNum() {
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNum(Integer num) {
|
||||||
|
this.num = num;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOwnSpec() {
|
||||||
|
return ownSpec;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOwnSpec(String ownSpec) {
|
||||||
|
this.ownSpec = ownSpec;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Cart{" +
|
||||||
|
"userId=" + userId +
|
||||||
|
", skuId=" + skuId +
|
||||||
|
", title='" + title + '\'' +
|
||||||
|
", image='" + image + '\'' +
|
||||||
|
", price=" + price +
|
||||||
|
", num=" + num +
|
||||||
|
", ownSpec='" + ownSpec + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,83 @@
|
|||||||
|
package com.leyou.cart.properties;
|
||||||
|
|
||||||
|
import com.leyou.auth.utils.RsaUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import java.security.PublicKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* @Time: 2018-10-25 16:12
|
||||||
|
* @Feature: jwt属性
|
||||||
|
*/
|
||||||
|
//@ConfigurationProperties(prefix = "leyou.jwt")
|
||||||
|
@Configuration
|
||||||
|
@RefreshScope
|
||||||
|
public class JwtProperties {
|
||||||
|
/**
|
||||||
|
* 公钥
|
||||||
|
*/
|
||||||
|
private PublicKey publicKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公钥地址
|
||||||
|
*/
|
||||||
|
@Value("${leyou.jwt.pubKeyPath}")
|
||||||
|
private String pubKeyPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cookie名字
|
||||||
|
*/
|
||||||
|
@Value("${leyou.jwt.cookieName}")
|
||||||
|
private String cookieName;
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(JwtProperties.class);
|
||||||
|
|
||||||
|
public PublicKey getPublicKey() {
|
||||||
|
return publicKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublicKey(PublicKey publicKey) {
|
||||||
|
this.publicKey = publicKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPubKeyPath() {
|
||||||
|
return pubKeyPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPubKeyPath(String pubKeyPath) {
|
||||||
|
this.pubKeyPath = pubKeyPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCookieName() {
|
||||||
|
return cookieName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCookieName(String cookieName) {
|
||||||
|
this.cookieName = cookieName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Logger getLogger() {
|
||||||
|
return logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @PostConstruct :在构造方法执行之后执行该方法
|
||||||
|
*/
|
||||||
|
@PostConstruct
|
||||||
|
public void init(){
|
||||||
|
try {
|
||||||
|
// 获取公钥
|
||||||
|
this.publicKey = RsaUtils.getPublicKey(pubKeyPath);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("获取公钥失败!", e);
|
||||||
|
throw new RuntimeException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
package com.leyou.cart.service;
|
||||||
|
|
||||||
|
import com.leyou.cart.pojo.Cart;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* @Time: 2018-10-25 20:47
|
||||||
|
* @Feature:
|
||||||
|
*/
|
||||||
|
public interface CartService {
|
||||||
|
/**
|
||||||
|
* 添加购物车
|
||||||
|
* @param cart
|
||||||
|
*/
|
||||||
|
void addCart(Cart cart);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询购物车
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<Cart> queryCartList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新购物车中商品数量
|
||||||
|
* @param skuId
|
||||||
|
* @param num
|
||||||
|
*/
|
||||||
|
void updateNum(Long skuId, Integer num);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除购物车中的商品
|
||||||
|
* @param skuId
|
||||||
|
*/
|
||||||
|
void deleteCart(String skuId);
|
||||||
|
}
|
@ -0,0 +1,139 @@
|
|||||||
|
package com.leyou.cart.service.impl;
|
||||||
|
|
||||||
|
import com.leyou.auth.entity.UserInfo;
|
||||||
|
import com.leyou.cart.client.GoodsClient;
|
||||||
|
import com.leyou.cart.interceptor.LoginInterceptor;
|
||||||
|
import com.leyou.cart.pojo.Cart;
|
||||||
|
import com.leyou.cart.service.CartService;
|
||||||
|
import com.leyou.item.pojo.Sku;
|
||||||
|
import com.leyou.utils.JsonUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.BoundHashOperations;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
import org.springframework.data.redis.core.ValueOperations;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* @Time: 2018-10-25 20:48
|
||||||
|
* @Feature:
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class CartServiceImpl implements CartService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private StringRedisTemplate stringRedisTemplate;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisTemplate redisTemplate;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private GoodsClient goodsClient;
|
||||||
|
|
||||||
|
private static String KEY_PREFIX = "leyou:cart:uid:";
|
||||||
|
|
||||||
|
private final Logger logger = LoggerFactory.getLogger(CartServiceImpl.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加购物车
|
||||||
|
* @param cart
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void addCart(Cart cart) {
|
||||||
|
|
||||||
|
|
||||||
|
//1.获取用户
|
||||||
|
UserInfo userInfo = LoginInterceptor.getLoginUser();
|
||||||
|
//2.Redis的key
|
||||||
|
String key = KEY_PREFIX + userInfo.getId();
|
||||||
|
//3.获取hash操作对象
|
||||||
|
BoundHashOperations<String,Object,Object> hashOperations = this.stringRedisTemplate.boundHashOps(key);
|
||||||
|
//4.查询是否存在
|
||||||
|
Long skuId = cart.getSkuId();
|
||||||
|
Integer num = cart.getNum();
|
||||||
|
Boolean result = hashOperations.hasKey(skuId.toString());
|
||||||
|
if (result){
|
||||||
|
//5.存在,获取购物车数据
|
||||||
|
String json = hashOperations.get(skuId.toString()).toString();
|
||||||
|
cart = JsonUtils.parse(json,Cart.class);
|
||||||
|
//6.修改购物车数量
|
||||||
|
cart.setNum(cart.getNum() + num);
|
||||||
|
}else{
|
||||||
|
//7.不存在,新增购物车数据
|
||||||
|
cart.setUserId(userInfo.getId());
|
||||||
|
//8.其他商品信息,需要查询商品微服务
|
||||||
|
Sku sku = this.goodsClient.querySkuById(skuId);
|
||||||
|
cart.setImage(StringUtils.isBlank(sku.getImages()) ? "" : StringUtils.split(sku.getImages(),",")[0]);
|
||||||
|
cart.setPrice(sku.getPrice());
|
||||||
|
cart.setTitle(sku.getTitle());
|
||||||
|
cart.setOwnSpec(sku.getOwnSpec());
|
||||||
|
}
|
||||||
|
//9.将购物车数据写入redis
|
||||||
|
hashOperations.put(cart.getSkuId().toString(),JsonUtils.serialize(cart));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询购物车
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<Cart> queryCartList() {
|
||||||
|
//1.获取登录的用户信息
|
||||||
|
UserInfo userInfo = LoginInterceptor.getLoginUser();
|
||||||
|
//2.判断是否存在购物车
|
||||||
|
String key = KEY_PREFIX + userInfo.getId();
|
||||||
|
if (!this.stringRedisTemplate.hasKey(key)) {
|
||||||
|
//3.不存在直接返回
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
BoundHashOperations<String,Object,Object> hashOperations = this.stringRedisTemplate.boundHashOps(key);
|
||||||
|
List<Object> carts = hashOperations.values();
|
||||||
|
//4.判断是否有数据
|
||||||
|
if (CollectionUtils.isEmpty(carts)){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
//5.查询购物车数据
|
||||||
|
return carts.stream().map( o -> JsonUtils.parse(o.toString(),Cart.class)).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新购物车中商品数量
|
||||||
|
* @param skuId
|
||||||
|
* @param num
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void updateNum(Long skuId, Integer num) {
|
||||||
|
//1.获取登录用户
|
||||||
|
UserInfo userInfo = LoginInterceptor.getLoginUser();
|
||||||
|
String key = KEY_PREFIX + userInfo.getId();
|
||||||
|
BoundHashOperations<String,Object,Object> hashOperations = this.stringRedisTemplate.boundHashOps(key);
|
||||||
|
//2.获取购物车
|
||||||
|
String json = hashOperations.get(skuId.toString()).toString();
|
||||||
|
Cart cart = JsonUtils.parse(json,Cart.class);
|
||||||
|
cart.setNum(num);
|
||||||
|
//3.写入购物车
|
||||||
|
hashOperations.put(skuId.toString(),JsonUtils.serialize(cart));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除购物车中的商品
|
||||||
|
* @param skuId
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void deleteCart(String skuId) {
|
||||||
|
//1.获取登录用户
|
||||||
|
UserInfo userInfo = LoginInterceptor.getLoginUser();
|
||||||
|
String key = KEY_PREFIX + userInfo.getId();
|
||||||
|
BoundHashOperations<String,Object,Object> hashOperations = this.stringRedisTemplate.boundHashOps(key);
|
||||||
|
//2.删除商品
|
||||||
|
hashOperations.delete(skuId);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
spring:
|
||||||
|
cloud:
|
||||||
|
config:
|
||||||
|
name: cart
|
||||||
|
profile: dev
|
||||||
|
label: master
|
||||||
|
uri: http://127.0.0.1:10011
|
@ -0,0 +1,55 @@
|
|||||||
|
//package com.leyou.redis;
|
||||||
|
//
|
||||||
|
//import com.leyou.cart.LyCartApplication;
|
||||||
|
//import org.junit.Test;
|
||||||
|
//import org.junit.runner.RunWith;
|
||||||
|
//import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
//import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
//import org.springframework.data.redis.core.BoundHashOperations;
|
||||||
|
//import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
//import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
//import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
//
|
||||||
|
//import java.util.List;
|
||||||
|
//
|
||||||
|
///**
|
||||||
|
// * @Author: 98050
|
||||||
|
// * @Time: 2018-10-25 22:58
|
||||||
|
// * @Feature:
|
||||||
|
// */
|
||||||
|
//@RunWith(SpringRunner.class)
|
||||||
|
//@SpringBootTest(classes = LyCartApplication.class)
|
||||||
|
//public class RedisTest {
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// private StringRedisTemplate stringRedisTemplate;
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// private RedisTemplate<String,String> redisTemplate;
|
||||||
|
//
|
||||||
|
// @Test
|
||||||
|
// public void test(){
|
||||||
|
//
|
||||||
|
// BoundHashOperations<String,String,String> boundHashOperations = this.redisTemplate.boundHashOps("test");
|
||||||
|
//// boundHashOperations.put("1", "test1");
|
||||||
|
//// boundHashOperations.put("2", "test2");
|
||||||
|
//// boundHashOperations.put("3", "test3");
|
||||||
|
// List<String> result = boundHashOperations.values();
|
||||||
|
// for (Object o : result){
|
||||||
|
// System.out.println(o);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Test
|
||||||
|
// public void test2(){
|
||||||
|
//
|
||||||
|
// BoundHashOperations<String,String,String> boundHashOperations = this.redisTemplate.boundHashOps("test");
|
||||||
|
//// boundHashOperations.put("1", "test1");
|
||||||
|
//// boundHashOperations.put("2", "test2");
|
||||||
|
//// boundHashOperations.put("3", "test3");
|
||||||
|
// List<String> result = boundHashOperations.values();
|
||||||
|
// for (Object o : result){
|
||||||
|
// System.out.println(o);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
@ -0,0 +1,46 @@
|
|||||||
|
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>leyou-comments</artifactId>
|
||||||
|
<groupId>com.leyou.parent</groupId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.leyou.comments</groupId>
|
||||||
|
<artifactId>leyou-comments-interface</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.persistence</groupId>
|
||||||
|
<artifactId>persistence-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-webmvc</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<mainClass>com.xx.webapps.api.main.WebappsApiBidMain</mainClass>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>repackage</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
@ -0,0 +1,213 @@
|
|||||||
|
package com.leyou.comments.pojo;
|
||||||
|
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* @Time: 2018-11-26 14:45
|
||||||
|
* @Feature:
|
||||||
|
*/
|
||||||
|
public class Review implements Serializable {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
private String _id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单id
|
||||||
|
*/
|
||||||
|
private String orderid;
|
||||||
|
/**
|
||||||
|
* 商品id
|
||||||
|
*/
|
||||||
|
private String spuid;
|
||||||
|
/**
|
||||||
|
* 评论内容
|
||||||
|
*/
|
||||||
|
private String content;
|
||||||
|
/**
|
||||||
|
* 评论时间
|
||||||
|
*/
|
||||||
|
private Date publishtime;
|
||||||
|
/**
|
||||||
|
* 评论用户id
|
||||||
|
*/
|
||||||
|
private String userid;
|
||||||
|
/**
|
||||||
|
* 评论用户昵称
|
||||||
|
*/
|
||||||
|
private String nickname;
|
||||||
|
/**
|
||||||
|
* 评论的浏览量
|
||||||
|
*/
|
||||||
|
private Integer visits;
|
||||||
|
/**
|
||||||
|
* 评论的点赞数
|
||||||
|
*/
|
||||||
|
private Integer thumbup;
|
||||||
|
/**
|
||||||
|
* 评论中的图片
|
||||||
|
*/
|
||||||
|
private List<String> images;
|
||||||
|
/**
|
||||||
|
* 评论的回复数
|
||||||
|
*/
|
||||||
|
private Integer comment;
|
||||||
|
/**
|
||||||
|
* 该评论是否可以被回复
|
||||||
|
*/
|
||||||
|
private Boolean iscomment;
|
||||||
|
/**
|
||||||
|
* 该评论的上一级id
|
||||||
|
*/
|
||||||
|
private String parentid;
|
||||||
|
/**
|
||||||
|
* 是否是顶级评论
|
||||||
|
*/
|
||||||
|
private Boolean isparent;
|
||||||
|
/**
|
||||||
|
* 评论的类型
|
||||||
|
*/
|
||||||
|
private Integer type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* json转换需要
|
||||||
|
*/
|
||||||
|
public Review() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Review(String orderid,String spuid, String content, String userid, String nickname, List<String> images, Boolean iscomment, String parentid, Boolean isparent, Integer type) {
|
||||||
|
this.orderid = orderid;
|
||||||
|
this.spuid = spuid;
|
||||||
|
this.content = content;
|
||||||
|
this.userid = userid;
|
||||||
|
this.nickname = nickname;
|
||||||
|
this.images = images;
|
||||||
|
this.iscomment = iscomment;
|
||||||
|
this.parentid = parentid;
|
||||||
|
this.isparent = isparent;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOrderid() {
|
||||||
|
return orderid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrderid(String orderid) {
|
||||||
|
this.orderid = orderid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String get_id() {
|
||||||
|
return _id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set_id(String _id) {
|
||||||
|
this._id = _id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSpuid() {
|
||||||
|
return spuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSpuid(String spuid) {
|
||||||
|
this.spuid = spuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getContent() {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContent(String content) {
|
||||||
|
this.content = content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getPublishtime() {
|
||||||
|
return publishtime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublishtime(Date publishtime) {
|
||||||
|
this.publishtime = publishtime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUserid() {
|
||||||
|
return userid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserid(String userid) {
|
||||||
|
this.userid = userid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNickname() {
|
||||||
|
return nickname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNickname(String nickname) {
|
||||||
|
this.nickname = nickname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getVisits() {
|
||||||
|
return visits;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVisits(Integer visits) {
|
||||||
|
this.visits = visits;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getThumbup() {
|
||||||
|
return thumbup;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setThumbup(Integer thumbup) {
|
||||||
|
this.thumbup = thumbup;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getImages() {
|
||||||
|
return images;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImages(List<String> images) {
|
||||||
|
this.images = images;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getComment() {
|
||||||
|
return comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setComment(Integer comment) {
|
||||||
|
this.comment = comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIscomment() {
|
||||||
|
return iscomment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIscomment(Boolean comment) {
|
||||||
|
this.iscomment = comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getParentid() {
|
||||||
|
return parentid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParentid(String parentid) {
|
||||||
|
this.parentid = parentid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsparent() {
|
||||||
|
return isparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsparent(Boolean parent) {
|
||||||
|
this.isparent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(Integer type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
package com.leyou.comments.pojo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* @Time: 2018-11-26 16:46
|
||||||
|
* @Feature:
|
||||||
|
*/
|
||||||
|
public class Spit {
|
||||||
|
private String _id;
|
||||||
|
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
private String userid;
|
||||||
|
|
||||||
|
private String nickname;
|
||||||
|
|
||||||
|
private Integer visits;
|
||||||
|
|
||||||
|
public String get_id() {
|
||||||
|
return _id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set_id(String _id) {
|
||||||
|
this._id = _id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getContent() {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContent(String content) {
|
||||||
|
this.content = content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUserid() {
|
||||||
|
return userid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserid(String userid) {
|
||||||
|
this.userid = userid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNickname() {
|
||||||
|
return nickname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNickname(String nickname) {
|
||||||
|
this.nickname = nickname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getVisits() {
|
||||||
|
return visits;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVisits(Integer visits) {
|
||||||
|
this.visits = visits;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Spit{" +
|
||||||
|
"_id='" + _id + '\'' +
|
||||||
|
", content='" + content + '\'' +
|
||||||
|
", userid='" + userid + '\'' +
|
||||||
|
", nickname='" + nickname + '\'' +
|
||||||
|
", visits=" + visits +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package com.leyou.comments;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* @Time: 2018-11-29 15:41
|
||||||
|
* @Feature: 开启feign
|
||||||
|
*/
|
||||||
|
@SpringBootApplication
|
||||||
|
@EnableDiscoveryClient
|
||||||
|
@EnableFeignClients
|
||||||
|
public class LyCommentsApplication {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(LyCommentsApplication.class,args);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.leyou.comments.client;
|
||||||
|
|
||||||
|
import com.leyou.order.api.OrderApi;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* @Time: 2018-11-12 15:19
|
||||||
|
* @Feature: 订单接口
|
||||||
|
*/
|
||||||
|
@FeignClient(value = "order-service")
|
||||||
|
public interface OrderClient extends OrderApi {
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package com.leyou.comments.config;
|
||||||
|
|
||||||
|
import com.leyou.comments.properties.IdWorkerProperties;
|
||||||
|
import com.leyou.utils.IdWorker;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: 98050
|
||||||
|
* @create: 2018-10-27
|
||||||
|
**/
|
||||||
|
@Configuration
|
||||||
|
//@EnableConfigurationProperties(IdWorkerProperties.class)
|
||||||
|
public class IdWorkerConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public IdWorker idWorker(IdWorkerProperties prop) {
|
||||||
|
return new IdWorker(prop.getWorkerId(), prop.getDataCenterId());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
package com.leyou.comments.config;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||||
|
import com.leyou.comments.interceptor.LoginInterceptor;
|
||||||
|
import com.leyou.comments.properties.JwtProperties;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
|
import org.springframework.http.converter.StringHttpMessageConverter;
|
||||||
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||||
|
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||||
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: 98050
|
||||||
|
* @create: 2018-10-27
|
||||||
|
**/
|
||||||
|
@Configuration
|
||||||
|
@EnableWebMvc
|
||||||
|
//@EnableConfigurationProperties(JwtProperties.class)
|
||||||
|
public class MvcConfig implements WebMvcConfigurer {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private JwtProperties jwtProperties;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public LoginInterceptor loginInterceptor() {
|
||||||
|
return new LoginInterceptor(jwtProperties);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addInterceptors(InterceptorRegistry registry) {
|
||||||
|
|
||||||
|
List<String> excludePath = new ArrayList<>();
|
||||||
|
excludePath.add("/list");
|
||||||
|
excludePath.add("/commentId/**");
|
||||||
|
excludePath.add("/comment");
|
||||||
|
excludePath.add("/visit/**");
|
||||||
|
registry.addInterceptor(loginInterceptor())
|
||||||
|
.addPathPatterns("/**").excludePathPatterns(excludePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,140 @@
|
|||||||
|
package com.leyou.comments.controller;
|
||||||
|
|
||||||
|
import com.leyou.auth.entity.UserInfo;
|
||||||
|
import com.leyou.comments.bo.CommentRequestParam;
|
||||||
|
import com.leyou.comments.interceptor.LoginInterceptor;
|
||||||
|
import com.leyou.comments.pojo.Review;
|
||||||
|
import com.leyou.comments.service.CommentService;
|
||||||
|
import com.leyou.common.pojo.PageResult;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* @Time: 2018-11-26 21:30
|
||||||
|
* @Feature:
|
||||||
|
*/
|
||||||
|
@RequestMapping
|
||||||
|
@RestController
|
||||||
|
public class CommentController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CommentService commentService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisTemplate redisTemplate;
|
||||||
|
|
||||||
|
private final String THUMBUP_PREFIX = "thumbup";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询某一商品下的所有顶级评论
|
||||||
|
* @param requestParam
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("list")
|
||||||
|
public ResponseEntity findReviewBySpuId(@RequestBody CommentRequestParam requestParam){
|
||||||
|
Page<Review> result = commentService.findReviewBySpuId(requestParam);
|
||||||
|
if (result == null){
|
||||||
|
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
|
||||||
|
}
|
||||||
|
PageResult pageResult = new PageResult();
|
||||||
|
pageResult.setTotal(result.getTotalElements());
|
||||||
|
pageResult.setItems(result.getContent());
|
||||||
|
pageResult.setTotalPage((long)result.getTotalPages());
|
||||||
|
return ResponseEntity.ok(pageResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 评论点赞
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PutMapping("thumb/{id}")
|
||||||
|
public ResponseEntity<Boolean> updateThumbup(@PathVariable String id){
|
||||||
|
|
||||||
|
//1.首先判断当前用户是否点过赞
|
||||||
|
UserInfo userInfo = LoginInterceptor.getLoginUser();
|
||||||
|
String userId = userInfo.getId()+"";
|
||||||
|
if (redisTemplate.opsForValue().get(THUMBUP_PREFIX + userId + "_" + id) != null){
|
||||||
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
|
||||||
|
}
|
||||||
|
boolean result = this.commentService.updateThumbup(id);
|
||||||
|
if (!result){
|
||||||
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
|
||||||
|
}
|
||||||
|
redisTemplate.opsForValue().set(THUMBUP_PREFIX + userId + "_" + id,"1");
|
||||||
|
return ResponseEntity.ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 增加评论
|
||||||
|
* @param review
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("comment/{orderId}")
|
||||||
|
public ResponseEntity<Void> addReview(@PathVariable("orderId") Long orderId,@RequestBody Review review){
|
||||||
|
boolean result = this.commentService.add(orderId,review);
|
||||||
|
if (!result){
|
||||||
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResponseEntity.status(HttpStatus.CREATED).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据评论id查询评论
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/commentId/{id}")
|
||||||
|
public ResponseEntity<Review> findReviewById(@PathVariable("id") String id){
|
||||||
|
Review review = this.commentService.findOne(id);
|
||||||
|
if (review == null){
|
||||||
|
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok(review);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改评论
|
||||||
|
* @param review
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PutMapping("/comment")
|
||||||
|
public ResponseEntity<Void> updateReview(@RequestBody Review review){
|
||||||
|
this.commentService.update(review);
|
||||||
|
return ResponseEntity.status(HttpStatus.OK).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据评论id删除评论
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@DeleteMapping("/commentId/{id}")
|
||||||
|
public ResponseEntity<Void> deleteReview(@PathVariable("id") String id){
|
||||||
|
this.commentService.deleteById(id);
|
||||||
|
return ResponseEntity.status(HttpStatus.OK).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据评论id访问量加1
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PutMapping("visit/{id}")
|
||||||
|
public ResponseEntity<Void> updateReviewVisit(@PathVariable("id") String id){
|
||||||
|
boolean result = this.commentService.updateVisits(id);
|
||||||
|
if (!result){
|
||||||
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
|
||||||
|
}
|
||||||
|
return ResponseEntity.status(HttpStatus.OK).build();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package com.leyou.comments.dao;
|
||||||
|
|
||||||
|
|
||||||
|
import com.leyou.comments.pojo.Review;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* @Time: 2018-11-26 20:51
|
||||||
|
* @Feature:
|
||||||
|
*/
|
||||||
|
public interface CommentDao extends MongoRepository<Review,String> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询
|
||||||
|
* @param spuId
|
||||||
|
* @param pageable
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Page<Review> findReviewBySpuid(String spuId, Pageable pageable);
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.leyou.comments.dao;
|
||||||
|
|
||||||
|
|
||||||
|
import com.leyou.comments.pojo.Spit;
|
||||||
|
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* @Time: 2018-11-26 20:47
|
||||||
|
* @Feature:
|
||||||
|
*/
|
||||||
|
public interface SpitDao extends MongoRepository<Spit,String> {
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package com.leyou.comments.properties;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: 98050
|
||||||
|
* @create: 2018-10-27
|
||||||
|
**/
|
||||||
|
//@ConfigurationProperties(prefix = "leyou.worker")
|
||||||
|
@Configuration
|
||||||
|
@RefreshScope
|
||||||
|
public class IdWorkerProperties {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前机器id
|
||||||
|
*/
|
||||||
|
@Value("${leyou.worker.workerId}")
|
||||||
|
private long workerId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 序列号
|
||||||
|
*/
|
||||||
|
@Value("${leyou.worker.dataCenterId}")
|
||||||
|
private long dataCenterId;
|
||||||
|
|
||||||
|
public long getWorkerId() {
|
||||||
|
return workerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWorkerId(long workerId) {
|
||||||
|
this.workerId = workerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getDataCenterId() {
|
||||||
|
return dataCenterId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDataCenterId(long dataCenterId) {
|
||||||
|
this.dataCenterId = dataCenterId;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
package com.leyou.comments.properties;
|
||||||
|
|
||||||
|
import com.leyou.auth.utils.RsaUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import java.security.PublicKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: 9805
|
||||||
|
* @create: 2018-10-27
|
||||||
|
**/
|
||||||
|
//@ConfigurationProperties(prefix = "leyou.jwt")
|
||||||
|
@Configuration
|
||||||
|
@RefreshScope
|
||||||
|
public class JwtProperties {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公钥地址
|
||||||
|
*/
|
||||||
|
@Value("${leyou.jwt.pubKeyPath}")
|
||||||
|
private String pubKeyPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公钥
|
||||||
|
*/
|
||||||
|
private PublicKey publicKey;
|
||||||
|
|
||||||
|
@Value("${leyou.jwt.cookieName}")
|
||||||
|
private String cookieName;
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(JwtProperties.class);
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void init(){
|
||||||
|
try {
|
||||||
|
// 获取公钥和私钥
|
||||||
|
this.publicKey = RsaUtils.getPublicKey(pubKeyPath);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("初始化公钥失败!", e);
|
||||||
|
throw new RuntimeException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPubKeyPath() {
|
||||||
|
return pubKeyPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPubKeyPath(String pubKeyPath) {
|
||||||
|
this.pubKeyPath = pubKeyPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PublicKey getPublicKey() {
|
||||||
|
return publicKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublicKey(PublicKey publicKey) {
|
||||||
|
this.publicKey = publicKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCookieName() {
|
||||||
|
return cookieName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCookieName(String cookieName) {
|
||||||
|
this.cookieName = cookieName;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
package com.leyou.comments.service;
|
||||||
|
|
||||||
|
import com.leyou.comments.bo.CommentRequestParam;
|
||||||
|
import com.leyou.comments.pojo.Review;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* @Time: 2018-11-26 15:40
|
||||||
|
* @Feature:
|
||||||
|
*/
|
||||||
|
public interface CommentService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据评论id查询
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Review findOne(String id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增评论
|
||||||
|
* @param review
|
||||||
|
* @param orderId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
boolean add(Long orderId,Review review);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改评论
|
||||||
|
*
|
||||||
|
* @param review
|
||||||
|
*/
|
||||||
|
void update(Review review);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除指定评论
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
void deleteById(String id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询某一商品下的所有顶级评论
|
||||||
|
* @param commentRequestParam
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Page<Review> findReviewBySpuId(CommentRequestParam commentRequestParam);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 评论点赞
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
boolean updateThumbup(String id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 浏览量增1
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
boolean updateVisits(String id);
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
spring:
|
||||||
|
cloud:
|
||||||
|
config:
|
||||||
|
name: comments
|
||||||
|
profile: dev
|
||||||
|
label: master
|
||||||
|
uri: http://127.0.0.1:10011
|
@ -0,0 +1,70 @@
|
|||||||
|
//import com.leyou.comments.LyCommentsApplication;
|
||||||
|
//import com.leyou.comments.dao.CommentDao;
|
||||||
|
//import com.leyou.comments.pojo.Review;
|
||||||
|
//import com.leyou.comments.service.CommentService;
|
||||||
|
//import org.junit.Test;
|
||||||
|
//import org.junit.runner.RunWith;
|
||||||
|
//import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
//import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
//import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
//
|
||||||
|
//import java.util.ArrayList;
|
||||||
|
//import java.util.List;
|
||||||
|
//
|
||||||
|
///**
|
||||||
|
// * @Author: 98050
|
||||||
|
// * @Time: 2018-12-09 20:37
|
||||||
|
// * @Feature:
|
||||||
|
// */
|
||||||
|
//@RunWith(SpringRunner.class)
|
||||||
|
//@SpringBootTest(classes = LyCommentsApplication.class)
|
||||||
|
//public class CommentsTest {
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// private CommentService commentService;
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// private CommentDao commentDao;
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 为spuId为2的商品添加100条评顶级论数据
|
||||||
|
// */
|
||||||
|
// @Test
|
||||||
|
// public void LoadData(){
|
||||||
|
// for (int i = 0; i < 100; i++) {
|
||||||
|
// String spuId = "2";
|
||||||
|
// String content = "手机不错"+i;
|
||||||
|
// String userId = (35 + i) + "";
|
||||||
|
// String nickname = "username"+i;
|
||||||
|
// List<String> images = new ArrayList<>();
|
||||||
|
// boolean iscomment = i % 2 == 0;
|
||||||
|
// String parentId = 0 + "";
|
||||||
|
// boolean isparent = true;
|
||||||
|
// int type = i % 5;
|
||||||
|
// //Review review = new Review(spuId, content, userId, nickname, images, iscomment, parentId,isparent,type);
|
||||||
|
//
|
||||||
|
// //commentService.add(review);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Test
|
||||||
|
// public void LoadOneData(){
|
||||||
|
// String spuId = "2";
|
||||||
|
// String content = "苹果手机不错";
|
||||||
|
// String userId = 36 + "";
|
||||||
|
// String nickname = "username1";
|
||||||
|
// List<String> images = new ArrayList<>();
|
||||||
|
// boolean iscomment = true;
|
||||||
|
// String parentId = "1071767095416725504";
|
||||||
|
// boolean isparent = false;
|
||||||
|
// int type = 4;
|
||||||
|
// //Review review = new Review(spuId, content, userId, nickname, images, iscomment, parentId,isparent,type);
|
||||||
|
//
|
||||||
|
// //commentService.add(review);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Test
|
||||||
|
// public void delete(){
|
||||||
|
// commentDao.deleteAll();
|
||||||
|
// }
|
||||||
|
//}
|
@ -0,0 +1,46 @@
|
|||||||
|
//import com.leyou.comments.LyCommentsApplication;
|
||||||
|
//import com.leyou.comments.dao.SpitDao;
|
||||||
|
//import com.leyou.comments.pojo.Spit;
|
||||||
|
//import org.junit.Test;
|
||||||
|
//import org.junit.runner.RunWith;
|
||||||
|
//import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
//import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
//import org.springframework.data.mongodb.core.MongoTemplate;
|
||||||
|
//import org.springframework.data.mongodb.core.query.Criteria;
|
||||||
|
//import org.springframework.data.mongodb.core.query.Query;
|
||||||
|
//import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
//
|
||||||
|
//import java.util.List;
|
||||||
|
//
|
||||||
|
//@RunWith(SpringRunner.class)
|
||||||
|
//@SpringBootTest(classes = LyCommentsApplication.class)
|
||||||
|
//public class LeyouReviewServieApplicationTests {
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// private SpitDao spitDAO;
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// private MongoTemplate mongoTemplate;
|
||||||
|
//
|
||||||
|
// @Test
|
||||||
|
// public void contextLoads() {
|
||||||
|
// Spit spit = new Spit();
|
||||||
|
// spit.set_id("5");
|
||||||
|
// spit.setContent("123123123");
|
||||||
|
// spit.setNickname("123123123");
|
||||||
|
// spit.setUserid("123121");
|
||||||
|
// spit.setVisits(1234);
|
||||||
|
// spitDAO.save(spit);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Test
|
||||||
|
// public void findTest(){
|
||||||
|
// Criteria criteria = new Criteria();
|
||||||
|
// criteria.andOperator(Criteria.where("_id").is("5"),Criteria.where("visits").is(1234));
|
||||||
|
// List<Spit> spits = this.mongoTemplate.find(new Query(criteria),Spit.class);
|
||||||
|
// System.out.println("数量:"+spits.size());
|
||||||
|
// for (Spit spit : spits){
|
||||||
|
// System.out.println(spit);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
@ -0,0 +1,21 @@
|
|||||||
|
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>leyou</artifactId>
|
||||||
|
<groupId>com.leyou.parent</groupId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.leyou.parent</groupId>
|
||||||
|
<artifactId>leyou-comments</artifactId>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<modules>
|
||||||
|
<module>leyou-comments-service</module>
|
||||||
|
<module>leyou-comments-interface</module>
|
||||||
|
</modules>
|
||||||
|
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,58 @@
|
|||||||
|
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>leyou</artifactId>
|
||||||
|
<groupId>com.leyou.parent</groupId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.leyou.common</groupId>
|
||||||
|
<artifactId>leyou-common</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.servlet</groupId>
|
||||||
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--日志包-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-logging</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.security</groupId>
|
||||||
|
<artifactId>spring-security-crypto</artifactId>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.tomcat.embed</groupId>
|
||||||
|
<artifactId>tomcat-embed-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,61 @@
|
|||||||
|
package com.leyou.common.pojo;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author li
|
||||||
|
* @param <T>
|
||||||
|
*/
|
||||||
|
public class PageResult<T> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 总条数
|
||||||
|
*/
|
||||||
|
private Long total;
|
||||||
|
/**
|
||||||
|
* 总页数
|
||||||
|
*/
|
||||||
|
private Long totalPage;
|
||||||
|
/**
|
||||||
|
* 当前页数据
|
||||||
|
*/
|
||||||
|
private List<T> items;
|
||||||
|
|
||||||
|
public PageResult() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public PageResult(Long total, List<T> items) {
|
||||||
|
this.total = total;
|
||||||
|
this.items = items;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PageResult(Long total, Long totalPage, List<T> items) {
|
||||||
|
this.total = total;
|
||||||
|
this.totalPage = totalPage;
|
||||||
|
this.items = items;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getTotal() {
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTotal(Long total) {
|
||||||
|
this.total = total;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<T> getItems() {
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setItems(List<T> items) {
|
||||||
|
this.items = items;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getTotalPage() {
|
||||||
|
return totalPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTotalPage(Long totalPage) {
|
||||||
|
this.totalPage = totalPage;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.leyou.myexception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* @Time: 2018-11-05 16:09
|
||||||
|
* @Feature:
|
||||||
|
*/
|
||||||
|
public enum LyException {
|
||||||
|
/**
|
||||||
|
* 分类信息无法找到
|
||||||
|
*/
|
||||||
|
CATEGORY_NOT_FOUND,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 品牌信息无法找到
|
||||||
|
*/
|
||||||
|
BRAND_NOT_FOUND,
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.leyou.myexception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* @Time: 2018-11-05 16:07
|
||||||
|
* @Feature:
|
||||||
|
*/
|
||||||
|
public class MyException extends RuntimeException {
|
||||||
|
|
||||||
|
public MyException(LyException exception) {
|
||||||
|
super(exception.toString());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,81 @@
|
|||||||
|
package com.leyou.response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* @Time: 2018-11-24 21:37
|
||||||
|
* @Feature: 返回状态码
|
||||||
|
*/
|
||||||
|
public class CodeMsg {
|
||||||
|
|
||||||
|
private int code;
|
||||||
|
private String msg;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通用的错误码
|
||||||
|
*/
|
||||||
|
public static CodeMsg SUCCESS = new CodeMsg(0, "success");
|
||||||
|
public static CodeMsg SERVER_ERROR = new CodeMsg(500100, "服务端异常");
|
||||||
|
public static CodeMsg BIND_ERROR = new CodeMsg(500101, "参数校验异常:%s");
|
||||||
|
public static CodeMsg REQUEST_ILLEGAL = new CodeMsg(500102, "请求非法");
|
||||||
|
public static CodeMsg ACCESS_LIMIT_REACHED= new CodeMsg(500104, "访问太频繁!");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录模块 5002XX
|
||||||
|
*/
|
||||||
|
public static CodeMsg LOGIN_ERROR = new CodeMsg(500210, "用户未登录");
|
||||||
|
public static CodeMsg PASSWORD_EMPTY = new CodeMsg(500211, "登录密码不能为空");
|
||||||
|
public static CodeMsg MOBILE_EMPTY = new CodeMsg(500212, "手机号不能为空");
|
||||||
|
public static CodeMsg MOBILE_ERROR = new CodeMsg(500213, "手机号格式错误");
|
||||||
|
public static CodeMsg MOBILE_NOT_EXIST = new CodeMsg(500214, "手机号不存在");
|
||||||
|
public static CodeMsg PASSWORD_ERROR = new CodeMsg(500215, "密码错误");
|
||||||
|
|
||||||
|
|
||||||
|
//商品模块 5003XX
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单模块 5004XX
|
||||||
|
*/
|
||||||
|
public static CodeMsg ORDER_NOT_EXIST = new CodeMsg(500400, "订单不存在");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 秒杀模块 5005XX
|
||||||
|
*/
|
||||||
|
public static CodeMsg MIAO_SHA_OVER = new CodeMsg(500500, "商品已经秒杀完毕");
|
||||||
|
public static CodeMsg REPEATE_MIAOSHA = new CodeMsg(500501, "不能重复秒杀");
|
||||||
|
public static CodeMsg MIAOSHA_FAIL = new CodeMsg(500502, "秒杀失败");
|
||||||
|
|
||||||
|
|
||||||
|
private CodeMsg( ) {
|
||||||
|
}
|
||||||
|
|
||||||
|
private CodeMsg( int code,String msg ) {
|
||||||
|
this.code = code;
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
public void setCode(int code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
public String getMsg() {
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
public void setMsg(String msg) {
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CodeMsg fillArgs(Object... args) {
|
||||||
|
int code = this.code;
|
||||||
|
String message = String.format(this.msg, args);
|
||||||
|
return new CodeMsg(code, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "CodeMsg [code=" + code + ", msg=" + msg + "]";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
package com.leyou.response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* @Time: 2018-11-24 21:41
|
||||||
|
* @Feature: 返回结果
|
||||||
|
*/
|
||||||
|
public class Result<T> {
|
||||||
|
|
||||||
|
private int code;
|
||||||
|
private String msg;
|
||||||
|
private T data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 成功时候的调用
|
||||||
|
* */
|
||||||
|
public static <T> Result<T> success(T data){
|
||||||
|
Result<T> result = new Result<T>(data);
|
||||||
|
result.code = CodeMsg.SUCCESS.getCode();
|
||||||
|
return new Result<T>(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 失败时候的调用
|
||||||
|
* */
|
||||||
|
public static <T> Result<T> error(CodeMsg codeMsg){
|
||||||
|
return new Result<T>(codeMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Result(T data) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Result(int code, String msg) {
|
||||||
|
this.code = code;
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Result(CodeMsg codeMsg) {
|
||||||
|
if(codeMsg != null) {
|
||||||
|
this.code = codeMsg.getCode();
|
||||||
|
this.msg = codeMsg.getMsg();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
public void setCode(int code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
public String getMsg() {
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
public void setMsg(String msg) {
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
public T getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
public void setData(T data) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package com.leyou.utils;
|
||||||
|
|
||||||
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* @Time: 2018-10-23 10:49
|
||||||
|
* @Feature: 密码加密
|
||||||
|
*/
|
||||||
|
public class CodecUtils {
|
||||||
|
|
||||||
|
public static String passwordBcryptEncode(String username,String password){
|
||||||
|
|
||||||
|
return new BCryptPasswordEncoder().encode(username + password);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Boolean passwordConfirm(String rawPassword,String encodePassword){
|
||||||
|
return new BCryptPasswordEncoder().matches(rawPassword,encodePassword);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.leyou.utils;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Author: 98050
|
||||||
|
* Time: 2018-08-05 15:58
|
||||||
|
* Feature:
|
||||||
|
*/
|
||||||
|
public class Test {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
List<Integer> lis = Arrays.asList(1, 2, 3);
|
||||||
|
lis.forEach(num -> System.out.println(num));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.leyou.config;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.config.server.EnableConfigServer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* @Time: 2018-11-28 16:39
|
||||||
|
* @Feature: 配置中心
|
||||||
|
*/
|
||||||
|
@EnableConfigServer
|
||||||
|
@SpringBootApplication
|
||||||
|
public class LyConfigApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(LyConfigApplication.class,args);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package com.leyou.config.myconfig;
|
||||||
|
|
||||||
|
import come.leyou.config.filter.MyFilter;
|
||||||
|
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* @Time: 2018-11-30 20:56
|
||||||
|
* @Feature:
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class MvcConfig implements WebMvcConfigurer {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public FilterRegistrationBean someFilterRegistration1() {
|
||||||
|
//新建过滤器注册类
|
||||||
|
FilterRegistrationBean registration = new FilterRegistrationBean();
|
||||||
|
// 添加我们写好的过滤器
|
||||||
|
registration.setFilter( new MyFilter());
|
||||||
|
// 设置过滤器的URL模式
|
||||||
|
registration.addUrlPatterns("/*");
|
||||||
|
return registration;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
package come.leyou.config.filter;
|
||||||
|
|
||||||
|
import javax.servlet.ReadListener;
|
||||||
|
import javax.servlet.ServletInputStream;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletRequestWrapper;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
/**
|
||||||
|
* @author 98050
|
||||||
|
*/
|
||||||
|
public class CustometRequestWrapper extends HttpServletRequestWrapper {
|
||||||
|
public CustometRequestWrapper(HttpServletRequest request) {
|
||||||
|
super(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ServletInputStream getInputStream() throws IOException {
|
||||||
|
byte[] bytes = new byte[0];
|
||||||
|
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
|
||||||
|
|
||||||
|
return new ServletInputStream() {
|
||||||
|
@Override
|
||||||
|
public boolean isFinished() {
|
||||||
|
return byteArrayInputStream.read() == -1 ? true:false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isReady() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setReadListener(ReadListener readListener) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int read() throws IOException {
|
||||||
|
return byteArrayInputStream.read();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
package come.leyou.config.filter;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import javax.servlet.*;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* @Time: 2018-11-30 20:59
|
||||||
|
* @Feature:
|
||||||
|
*/
|
||||||
|
public class MyFilter implements Filter {
|
||||||
|
|
||||||
|
private Logger logger = LoggerFactory.getLogger(MyFilter.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(FilterConfig filterConfig) throws ServletException {
|
||||||
|
logger.info("过滤器启动");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
|
||||||
|
HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
|
||||||
|
HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;
|
||||||
|
String url = httpServletRequest.getRequestURI();
|
||||||
|
|
||||||
|
//过滤/actuator/bus-refresh请求
|
||||||
|
String suffix = "/bus-refresh";
|
||||||
|
if (!url.endsWith(suffix)){
|
||||||
|
filterChain.doFilter(servletRequest,servletResponse);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CustometRequestWrapper requestWrapper = new CustometRequestWrapper(httpServletRequest);
|
||||||
|
filterChain.doFilter(requestWrapper,servletResponse);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroy() {
|
||||||
|
logger.info("过滤器销毁");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
server:
|
||||||
|
port: 10011
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: leyou-config
|
||||||
|
cloud:
|
||||||
|
config:
|
||||||
|
server:
|
||||||
|
git:
|
||||||
|
uri: https://github.com/lyj8330328/leyou-config.git
|
||||||
|
rabbitmq:
|
||||||
|
host: 192.168.19.121
|
||||||
|
username: /leyou
|
||||||
|
password: leyou
|
||||||
|
virtual-host: /leyou
|
||||||
|
|
||||||
|
|
||||||
|
management: #暴露触发消息总线的地址
|
||||||
|
endpoints:
|
||||||
|
web:
|
||||||
|
exposure:
|
||||||
|
include: bus-refresh
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.leyou.client;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* Time: 2018-10-17 18:59
|
||||||
|
* Feature:品牌FeignClient
|
||||||
|
*/
|
||||||
|
|
||||||
|
import com.leyou.item.api.BrandApi;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
|
||||||
|
@FeignClient(value = "item-service")
|
||||||
|
public interface BrandClient extends BrandApi {
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.leyou.client;
|
||||||
|
|
||||||
|
import com.leyou.item.api.CategoryApi;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* Time: 2018-10-17 19:01
|
||||||
|
* Feature:商品分类FeignClient
|
||||||
|
*/
|
||||||
|
@FeignClient(value = "item-service")
|
||||||
|
public interface CategoryClient extends CategoryApi {
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.leyou.client;
|
||||||
|
|
||||||
|
import com.leyou.item.api.GoodsApi;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* Time: 2018-10-17 18:55
|
||||||
|
* Feature:商品FeignClient
|
||||||
|
*/
|
||||||
|
@FeignClient(value = "item-service")
|
||||||
|
public interface GoodsClient extends GoodsApi {
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.leyou.client;
|
||||||
|
|
||||||
|
import com.leyou.item.api.SpecApi;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* Time: 2018-10-17 19:01
|
||||||
|
* Feature:spec FeignClient
|
||||||
|
*/
|
||||||
|
@FeignClient(value = "item-service")
|
||||||
|
public interface SpecClient extends SpecApi {
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.leyou.client;
|
||||||
|
|
||||||
|
import com.leyou.item.api.SpuApi;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* Time: 2018-10-17 19:02
|
||||||
|
* Feature:
|
||||||
|
*/
|
||||||
|
@FeignClient(value = "item-service")
|
||||||
|
public interface SpuClient extends SpuApi {
|
||||||
|
}
|
@ -0,0 +1,79 @@
|
|||||||
|
package com.leyou.controller;
|
||||||
|
|
||||||
|
import com.leyou.service.GoodsHtmlService;
|
||||||
|
import com.leyou.service.GoodsService;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.BoundHashOperations;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
import org.thymeleaf.context.WebContext;
|
||||||
|
import org.thymeleaf.spring5.context.webflux.SpringWebFluxContext;
|
||||||
|
import org.thymeleaf.spring5.view.ThymeleafViewResolver;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* Time: 2018-10-17 16:06
|
||||||
|
* Feature: 商品详情页面跳转
|
||||||
|
*/
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("item")
|
||||||
|
public class GoodsController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private GoodsService goodsService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private GoodsHtmlService goodsHtmlService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private StringRedisTemplate stringRedisTemplate;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ThymeleafViewResolver thymeleafViewResolver;
|
||||||
|
|
||||||
|
private static String KEY_PREFIX = "leyou:goods:detail:";
|
||||||
|
|
||||||
|
@GetMapping(value = "{id}.html",produces = "text/html")
|
||||||
|
@ResponseBody
|
||||||
|
public String toItemPage(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable("id")String id) throws InterruptedException, ExecutionException {
|
||||||
|
Long idN = Long.parseLong(id);
|
||||||
|
//加载数据
|
||||||
|
Map<String, Object> modelMap = this.goodsService.loadModel(idN);
|
||||||
|
//把数据放入模型中
|
||||||
|
model.addAllAttributes(modelMap);
|
||||||
|
//页面静态化
|
||||||
|
// this.goodsHtmlService.asyncExecute(idN);
|
||||||
|
// return "item";
|
||||||
|
BoundHashOperations<String,Object,Object> hashOperations = this.stringRedisTemplate.boundHashOps(KEY_PREFIX+id);
|
||||||
|
String html = (String) hashOperations.get(id);
|
||||||
|
/**
|
||||||
|
* 先取缓存
|
||||||
|
*/
|
||||||
|
if (StringUtils.isNotEmpty(html)){
|
||||||
|
//不空,则返回
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
//手动渲染模板
|
||||||
|
WebContext context = new WebContext(request,response,request.getServletContext(),request.getLocale(),model.asMap());
|
||||||
|
html = thymeleafViewResolver.getTemplateEngine().process("item",context);
|
||||||
|
if (StringUtils.isNotEmpty(html)){
|
||||||
|
//不空,放入缓存
|
||||||
|
//设置有效期60秒
|
||||||
|
hashOperations.put(id,html);
|
||||||
|
hashOperations.expire(60, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.leyou.service;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* Time: 2018-10-17 19:27
|
||||||
|
* Feature:商品详情页后台
|
||||||
|
*/
|
||||||
|
public interface GoodsService {
|
||||||
|
/**
|
||||||
|
* 商品详细信息
|
||||||
|
* @param spuId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Map<String,Object> loadModel(Long spuId) throws InterruptedException, ExecutionException;
|
||||||
|
}
|
@ -0,0 +1,86 @@
|
|||||||
|
package com.leyou.service.impl;
|
||||||
|
|
||||||
|
import com.leyou.service.GoodsHtmlService;
|
||||||
|
import com.leyou.service.GoodsService;
|
||||||
|
|
||||||
|
|
||||||
|
import com.leyou.utils.ThreadUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.thymeleaf.TemplateEngine;
|
||||||
|
import org.thymeleaf.context.Context;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 98050
|
||||||
|
* @Time: 2018-10-19 09:46
|
||||||
|
* @Feature: 实现页面静态化接口
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class GoodsHtmlServiceImpl implements GoodsHtmlService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private GoodsService goodsService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TemplateEngine templateEngine;
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(GoodsHtmlService.class);
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createHtml(Long spuId) throws InterruptedException, ExecutionException {
|
||||||
|
PrintWriter writer = null;
|
||||||
|
|
||||||
|
//获取页面数据
|
||||||
|
Map<String,Object> spuMap = this.goodsService.loadModel(spuId);
|
||||||
|
//创建Thymeleaf上下文对象
|
||||||
|
Context context = new Context();
|
||||||
|
//把数据放入上下文对象
|
||||||
|
context.setVariables(spuMap);
|
||||||
|
|
||||||
|
//创建输出流
|
||||||
|
File file = new File("D:\\nginx-1.12.2\\html\\item\\"+spuId+".html");
|
||||||
|
try {
|
||||||
|
writer = new PrintWriter(file);
|
||||||
|
//执行页面静态化方法
|
||||||
|
templateEngine.process("item",context,writer);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
LOGGER.error("页面静态化出错:{}"+e,spuId);
|
||||||
|
}finally {
|
||||||
|
if (writer != null){
|
||||||
|
writer.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新建线程处理页面静态化
|
||||||
|
* @param spuId
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void asyncExecute(Long spuId) {
|
||||||
|
ThreadUtils.execute(() -> {
|
||||||
|
try {
|
||||||
|
createHtml(spuId);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (ExecutionException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteHtml(Long id) {
|
||||||
|
File file = new File("D:\\nginx-1.12.2\\html\\item\\"+id+".html");
|
||||||
|
file.deleteOnExit();
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue