bianzhenhua123 1 hónapja
szülő
commit
bc8ddb662b

+ 11 - 0
micro-common/pom.xml

@@ -12,4 +12,15 @@
     <artifactId>micro-common</artifactId>
     <version>1.0.0</version>
 
+    <dependencies>
+        <dependency>
+            <groupId>com.github.dozermapper</groupId>
+            <artifactId>dozer-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+        </dependency>
+    </dependencies>
+
 </project>

+ 28 - 0
micro-common/src/main/java/com/poyee/common/SystemConfig.java

@@ -0,0 +1,28 @@
+package com.poyee.common;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+/*
+@Configuration
+@ConfigurationProperties(prefix = "poyee")
+public class SystemConfig {
+    private String name;
+    private int version;
+
+    // Getters and Setters
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public int getVersion() {
+        return version;
+    }
+
+    public void setVersion(int version) {
+        this.version = version;
+    }
+}*/

+ 166 - 0
micro-common/src/main/java/com/poyee/common/dto/InDto.java

@@ -0,0 +1,166 @@
+package com.poyee.common.dto;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.poyee.common.exception.ServiceException;
+import com.poyee.common.utils.bean.DozerUtils;
+import lombok.Data;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.util.CollectionUtils;
+import org.springframework.util.StringUtils;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 接口入参
+ */
+@Data
+@Slf4j
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class InDto implements Serializable {
+    private static final long serialVersionUID = 1L;
+    //appid
+    private String appid;
+    //openid
+    private String openid;
+    //unionid
+    private String unionid;
+    //用户类型: WX_WEB (微信公众号) WX_APPLET (微信小程序) THIRD (第三方) WX_AUTH(微信授权登陆)
+    private String userType;
+    //userid
+    private Integer userId;
+    //账号
+    private String username;
+    //每页数据条数
+    private Integer pageSize =10;
+    //页码数
+    private Integer pageNo=1;
+    //其他数据
+    private Map<String,Object> data;
+    //部门id
+    private Integer departId;
+
+    private Integer offset;
+
+    private long timestamp;
+
+    private String version;
+    // 极光id
+    private String smsRegisterId;
+    //签名
+    private String sign;
+
+    public Object get(String key){
+        if(null != data && !data.isEmpty()){
+            return this.data.get(key);
+        }
+        return null;
+    }
+    public Object getDefault(String key,Object value){
+        if(null != data && !data.isEmpty()){
+            try{
+                return null == this.data.get(key) ? value : this.data.get(key);
+            }catch (Exception e){
+            }
+        }
+        return value;
+    }
+    public String getString(String key){
+        if(null != data && !data.isEmpty()&&this.data.containsKey(key)){
+            return null != this.data.get(key) ? String.valueOf(this.data.get(key)) : null;
+        }
+        return null;
+    }
+
+    public Boolean existKeyString(String key){
+        if(null != data && !data.isEmpty()&&this.data.containsKey(key)){
+            return true;
+        }
+        return false;
+    }
+
+    public Integer getIntegerParam(String key) {
+        if (CollectionUtils.isEmpty(data)) {
+            return null;
+        }
+        return (Integer) this.data.get(key);
+    }
+
+    public boolean getBooleanParam(String key) {
+        if (CollectionUtils.isEmpty(data)) {
+            return false;
+        }
+        Boolean b = (Boolean) this.data.get(key);
+        return b != null && b;
+    }
+
+    public String getStringDefault(String key,String value){
+        if(null != data && !data.isEmpty()){
+            try {
+                String ret = String.valueOf(this.data.get(key));
+                return StringUtils.isEmpty(ret) ? value : ("null".equals(ret) ? value : ret);
+            }catch (Exception e){}
+        }
+        return value;
+    }
+    public Integer getIntegerDefault(String key,Integer value){
+        if(null != data && !data.isEmpty()){
+            try {
+                Integer ret = (Integer) this.data.get(key);
+                return StringUtils.isEmpty(ret) ? value :  ret;
+            }catch (Exception e){
+            }
+        }
+        return value;
+    }
+    public InDto put(String key ,Object value){
+        if(null == this.data) this.data = new HashMap<>();
+        this.data.put(key, value);
+        return this;
+    }
+    public InDto remove(String key){
+        if(null != this.data && !this.data.isEmpty()){
+            this.data.remove(key);
+        }
+        return this;
+    }
+
+    public Integer getPageSize() {
+        if(this.pageSize == null){
+            return pageSize;
+        }
+        return this.pageSize>0? this.pageSize:10;
+    }
+
+    public Integer getPageNo() {
+        if(this.pageNo == null){
+            return pageNo;
+        }
+        return this.pageNo>0? this.pageNo:1;
+    }
+
+    public Integer getOffset(){
+        if(this.pageNo==null||this.pageSize==null){
+            return 0;
+        }
+        return((pageNo) - 1 ) * pageSize;
+    }
+
+    /**
+     * 转换indto中data为指定参数
+     *
+     * @param param
+     * @param <T>
+     * @return
+     */
+    public <T> T buildParam( T param) {
+        try {
+            DozerUtils.copy(this.data,param);
+            return param;
+        } catch (Exception e) {
+            log.error("参数转换失败:", e);
+        }
+        throw new ServiceException(500, "参数获取失败!");
+    }
+}

+ 55 - 0
micro-common/src/main/java/com/poyee/common/exception/ServiceException.java

@@ -0,0 +1,55 @@
+package com.poyee.common.exception;
+
+import java.util.Map;
+
+/**
+ * 业务异常
+ * 
+ * @author zheng
+ */
+public class ServiceException extends RuntimeException {
+    private static final long serialVersionUID = 1L;
+
+    protected final String message;
+    protected int code=0;
+    /**特殊异常,抛出需要返回到前端的数据*/
+    protected Map<String, Object> data;
+
+    public ServiceException(String message)
+    {
+        this.code = -1;
+        this.message = message;
+    }
+
+    public ServiceException(int code, String message) {
+        this.message = message;
+        this.code = code;
+    }
+
+    public ServiceException(int code, String message, Map<String, Object> data) {
+        this.message = message;
+        this.code = code;
+        this.data = data;
+    }
+
+    public ServiceException(String message, Throwable e)
+    {
+        super(message, e);
+        this.message = message;
+    }
+
+    @Override
+    public String getMessage()
+    {
+        return message;
+    }
+
+    public int getCode()
+    {
+        return this.code;
+    }
+
+    public Map<String, Object> getData() {
+        return data;
+    }
+}

+ 67 - 0
micro-common/src/main/java/com/poyee/common/utils/bean/DozerUtils.java

@@ -0,0 +1,67 @@
+package com.poyee.common.utils.bean;
+
+import com.github.dozermapper.core.DozerBeanMapperBuilder;
+import com.github.dozermapper.core.Mapper;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+public class DozerUtils {
+
+    /**
+     * commonMapper,如果没有传mapper过来,默认使用这个
+     * dozer/dozer-mapping.xml 是相对resources目录的路径
+     */
+    public static Mapper  mapper = DozerBeanMapperBuilder.create()
+            .withMappingFiles("dozer/dozer-mapping.xml")
+            .build();
+
+    /**
+     * 单个对象转换
+     * 传入需要转换的对象,返回转换后的对象
+     * 用法:CommonDozerUtil.map(dto,Destination.class)
+     *
+     * @param source           源对象
+     * @param destinationClass
+     * @param <T>
+     * @return
+     */
+    public static <T> T map(Object source, Class<T> destinationClass) {
+        if (source != null) {
+            return mapper.map(source, destinationClass);
+        }
+        return null;
+    }
+
+    /**
+     * list转换
+     * 用法:CommonDozerUtil.mapList(list,Destination.class)
+     *
+     * @param sourceList
+     * @param destinationClass
+     * @param <T>
+     * @return
+     */
+    public static <T> List<T> mapList(Collection<?> sourceList, Class<T> destinationClass) {
+        List<T> destinationList = new ArrayList<>();
+        if (sourceList != null && sourceList.size() > 0) {
+            for (Object sourceObject : sourceList) {
+                T destinationObject = map(sourceObject, destinationClass);
+                destinationList.add(destinationObject);
+            }
+        }
+        return destinationList;
+    }
+
+    /**
+     * 将对象A的值拷贝到对象B中
+     *
+     * @param source            对象A
+     * @param destinationObject 对象B
+     */
+    public static void copy(Object source, Object destinationObject) {
+        mapper.map(source, destinationObject);
+    }
+
+}

+ 5 - 0
micro-service/src/main/java/com/poyee/service/HelloService.java

@@ -0,0 +1,5 @@
+package com.poyee.service;
+
+public interface HelloService {
+    String sayHello(String name);
+}

+ 12 - 0
micro-service/src/main/java/com/poyee/service/impl/HelloServiceImpl.java

@@ -0,0 +1,12 @@
+package com.poyee.service.impl;
+
+import com.poyee.service.HelloService;
+import org.springframework.stereotype.Service;
+
+@Service
+public class HelloServiceImpl implements HelloService {
+    @Override
+    public String sayHello(String name) {
+        return "bb";
+    }
+}

+ 75 - 38
pom.xml

@@ -2,12 +2,6 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
 	<modelVersion>4.0.0</modelVersion>
-	<parent>
-		<groupId>org.springframework.boot</groupId>
-		<artifactId>spring-boot-starter-parent</artifactId>
-		<version>3.5.6</version>
-		<relativePath/> <!-- lookup parent from repository -->
-	</parent>
 
 	<groupId>com.poyee</groupId>
 	<artifactId>poyee-micro</artifactId>
@@ -23,6 +17,16 @@
         <module>web-controller</module>
     </modules>
 
+    <properties>
+        <maven.compiler.source>8</maven.compiler.source>
+        <maven.compiler.target>8</maven.compiler.target>
+        <mahout.version>0.9</mahout.version>
+        <dozer.version>6.5.2</dozer.version>
+        <bee.version>1.17</bee.version>
+        <log.version>1.2.17</log.version>
+        <lombok.version>1.18.34</lombok.version>
+    </properties>
+
 	<dependencies>
 		<dependency>
 			<groupId>org.springframework.boot</groupId>
@@ -34,45 +38,78 @@
 			<artifactId>spring-boot-starter-test</artifactId>
 			<scope>test</scope>
 		</dependency>
-	</dependencies>
+    </dependencies>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-dependencies</artifactId>
+                <version>2.2.5.RELEASE</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+            <dependency>
+                <groupId>com.poyee</groupId>
+                <artifactId>micro-common</artifactId>
+                <version>1.0.0</version>
+            </dependency>
+
+            <dependency>
+                <groupId>com.poyee</groupId>
+                <artifactId>micro-dao</artifactId>
+                <version>1.0.0</version>
+            </dependency>
+
+            <dependency>
+                <groupId>com.poyee</groupId>
+                <artifactId>micro-manager</artifactId>
+                <version>1.0.0</version>
+            </dependency>
+
+            <dependency>
+                <groupId>com.poyee</groupId>
+                <artifactId>micro-service</artifactId>
+                <version>1.0.0</version>
+            </dependency>
+
+            <dependency>
+                <groupId>com.poyee</groupId>
+                <artifactId>web-controller</artifactId>
+                <version>1.0.0</version>
+            </dependency>
+
+            <dependency>
+                <groupId>org.projectlombok</groupId>
+                <artifactId>lombok</artifactId>
+                <version>${lombok.version}</version>
+                <scope>provided</scope>
+            </dependency>
+
+            <dependency>
+                <groupId>com.github.dozermapper</groupId>
+                <artifactId>dozer-core</artifactId>
+                <version>${dozer.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>log4j</groupId>
+                <artifactId>log4j</artifactId>
+                <version>${log.version}</version>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
 
     <build>
         <plugins>
             <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-compiler-plugin</artifactId>
-                <version>3.1</version>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <configuration>
+                    <mainClass>com.poyee.controller.DictApplication</mainClass>
+                </configuration>
             </plugin>
         </plugins>
     </build>
 
-    <repositories>
-        <repository>
-            <id>public</id>
-            <name>aliyun nexus</name>
-            <url>https://maven.aliyun.com/repository/public</url>
-            <releases>
-                <enabled>true</enabled>
-            </releases>
-        </repository>
-        <repository>
-            <id>zto-maven</id>
-            <url>https://dl.bintray.com/chocotan/maven</url>
-        </repository>
-    </repositories>
-
-    <pluginRepositories>
-        <pluginRepository>
-            <id>public</id>
-            <name>aliyun nexus</name>
-            <url>https://maven.aliyun.com/repository/public</url>
-            <releases>
-                <enabled>true</enabled>
-            </releases>
-            <snapshots>
-                <enabled>false</enabled>
-            </snapshots>
-        </pluginRepository>
-    </pluginRepositories>
 
 </project>

+ 0 - 13
web-controller/main/java/com/poyee/poyee_micro/PoyeeMicroApplication.java

@@ -1,13 +0,0 @@
-package com.poyee.poyee_micro;
-
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-
-@SpringBootApplication
-public class PoyeeMicroApplication {
-
-	public static void main(String[] args) {
-		SpringApplication.run(PoyeeMicroApplication.class, args);
-	}
-
-}

+ 0 - 1
web-controller/main/resources/application.yml

@@ -1 +0,0 @@
-spring.application.name=poyee-micro

+ 0 - 1
web-controller/pom.xml

@@ -16,7 +16,6 @@
             <groupId>com.poyee</groupId>
             <artifactId>micro-service</artifactId>
         </dependency>
-
     </dependencies>
 
 </project>

+ 14 - 0
web-controller/src/main/java/com/poyee/SvrApplication.java

@@ -0,0 +1,14 @@
+package com.poyee;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication(scanBasePackages = {"com.poyee"})
+public class SvrApplication {
+    public static void main(String[] args) {
+        System.out.println("SvrApplication start...");
+        SpringApplication.run(SvrApplication.class, args);
+        System.out.println("SvrApplication end...");
+    }
+}
+

+ 24 - 0
web-controller/src/main/java/com/poyee/controller/AppCommonController.java

@@ -0,0 +1,24 @@
+package com.poyee.controller;
+
+
+import com.poyee.common.dto.InDto;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * 抽取APP部分接口
+ * @author: zhenhua.bian
+ * @date: 2025/10/26
+ */
+
+@RestController
+@RequestMapping("/api/micro")
+public class AppCommonController {
+
+    @RequestMapping("/getDict")
+    public String getDict(@RequestBody InDto inDto) {
+        System.out.println(inDto);
+        return "hello world";
+    }
+}

+ 13 - 0
web-controller/src/main/java/com/poyee/controller/DictApplication.java

@@ -0,0 +1,13 @@
+package com.poyee.controller;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication(scanBasePackages = {"com.poyee"})
+public class DictApplication {
+    public static void main(String[] args) {
+        System.out.println("DictApplication start...");
+        SpringApplication.run(DictApplication.class, args);
+    }
+}
+

+ 0 - 0
web-controller/src/main/resources/application-dev.yml


+ 0 - 0
web-controller/src/main/resources/application-prod.yml


+ 24 - 0
web-controller/src/main/resources/application.yml

@@ -0,0 +1,24 @@
+# Nacos 配置
+nacos:
+  config:
+    server-addr: 127.0.0.1:8848
+    namespace: public
+    group: DEFAULT_GROUP
+    username: nacos
+    password: nacos
+  discovery:
+    server-addr: 127.0.0.1:8848
+    namespace: public
+    group: DEFAULT_GROUP
+    username: nacos
+    password: nacos
+
+# Dubbo 配置
+dubbo:
+  application:
+    name: poyee-micro-service
+  registry:
+    address: nacos://127.0.0.1:8848
+  protocol:
+    name: dubbo
+    port: 20880