From 750d08105ea928e547ec721c367a70ac946a0aef Mon Sep 17 00:00:00 2001
From: zhubaomin <zhubaomin>
Date: 星期五, 29 十一月 2024 14:54:49 +0800
Subject: [PATCH] App文件上传功能

---
 pipIrr-platform/pipIrr-web/pipIrr-web-app/src/main/java/com/dy/pipIrrApp/config/DataSourceFilterConfiguration.java    |   27 ++++++
 pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoIr/IrGroupClientMapper.java                        |   12 +++
 pipIrr-platform/pipIrr-global/src/main/resources/mapper/IrGroupClientMapper.xml                                       |   11 ++
 pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigatePlan/IrrigatePlanCtrl.java |   44 +++++++++++
 pipIrr-platform/pipIrr-web/pipIrr-web-app/src/main/java/com/dy/pipIrrApp/config/DataSourceFilter.java                 |   41 ++++++++++
 pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigatePlan/IrrigatePlanSv.java   |   32 ++++++++
 pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voIr/VoGroupSimple.java                               |   31 +++++++
 7 files changed, 198 insertions(+), 0 deletions(-)

diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoIr/IrGroupClientMapper.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoIr/IrGroupClientMapper.java
index cd16d9d..fbe5f1c 100644
--- a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoIr/IrGroupClientMapper.java
+++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoIr/IrGroupClientMapper.java
@@ -2,7 +2,10 @@
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.dy.pipIrrGlobal.pojoIr.IrGroupClient;
+import com.dy.pipIrrGlobal.voIr.VoGroupSimple;
 import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
 
 /**
  * @author ZhuBaoMin
@@ -24,4 +27,13 @@
     int updateByPrimaryKeySelective(IrGroupClient record);
 
     int updateByPrimaryKey(IrGroupClient record);
+
+    /**
+     * 鏍规嵁鍐滄埛缂栧彿鑾峰彇杞亴缁勫垪琛�
+     * @param clientId
+     * @return
+     */
+    List<VoGroupSimple> getGroupsByClientId(Long clientId);
+
+
 }
\ No newline at end of file
diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voIr/VoGroupSimple.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voIr/VoGroupSimple.java
new file mode 100644
index 0000000..c643c0b
--- /dev/null
+++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voIr/VoGroupSimple.java
@@ -0,0 +1,31 @@
+package com.dy.pipIrrGlobal.voIr;
+
+import com.alibaba.fastjson2.annotation.JSONField;
+import com.alibaba.fastjson2.writer.ObjectWriterImplToString;
+import com.dy.common.po.BaseEntity;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+import lombok.Data;
+
+/**
+ * @author ZhuBaoMin
+ * @date 2024-11-28 17:11
+ * @LastEditTime 2024-11-28 17:11
+ * @Description 杞亴缁勭畝鍗曡鍥惧璞�
+ */
+
+@Data
+@JsonPropertyOrder({"groupId", "groupCode"})
+public class VoGroupSimple implements BaseEntity {
+    public static final long serialVersionUID = 202411281712001L;
+
+    /**
+     * 杞亴缁処D
+     */
+    @JSONField(serializeUsing= ObjectWriterImplToString.class)
+    private Long groupId;
+
+    /**
+     * 杞亴缁勭紪鐮�
+     */
+    private String groupCode;
+}
diff --git a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/IrGroupClientMapper.xml b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/IrGroupClientMapper.xml
index 6a2a9a7..ea0fe18 100644
--- a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/IrGroupClientMapper.xml
+++ b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/IrGroupClientMapper.xml
@@ -99,4 +99,15 @@
       operate_time = #{operateTime,jdbcType=TIMESTAMP}
     where id = #{id,jdbcType=BIGINT}
   </update>
+
+  <!--鏍规嵁鍐滄埛缂栧彿鑾峰彇杞亴缁勫垪琛�-->
+  <select id="getGroupsByClientId" resultType="com.dy.pipIrrGlobal.voIr.VoGroupSimple">
+    SELECT
+      grp.id AS groupId,
+      grp.group_code AS groupCode
+    FROM ir_group_client gc
+           INNER JOIN ir_irrigate_group grp ON grp.id = gc.group_id
+    WHERE grp.deleted = 0 AND client_id = #{clientId}
+    ORDER BY grp.group_code
+  </select>
 </mapper>
\ No newline at end of file
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-app/src/main/java/com/dy/pipIrrApp/config/DataSourceFilter.java b/pipIrr-platform/pipIrr-web/pipIrr-web-app/src/main/java/com/dy/pipIrrApp/config/DataSourceFilter.java
new file mode 100644
index 0000000..9c18f2c
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-app/src/main/java/com/dy/pipIrrApp/config/DataSourceFilter.java
@@ -0,0 +1,41 @@
+package com.dy.pipIrrApp.config;
+
+import com.dy.common.multiDataSource.DataSourceContext;
+import jakarta.servlet.*;
+import jakarta.servlet.http.HttpServletRequest;
+import lombok.extern.slf4j.Slf4j;
+
+import java.io.IOException;
+
+/**
+ * @author ZhuBaoMin
+ * @date 2024-11-29 14:24
+ * @LastEditTime 2024-11-29 14:24
+ * @Description
+ */
+
+@Slf4j
+public class DataSourceFilter implements Filter {
+
+    @Override
+    public void init(FilterConfig filterConfig) throws ServletException  {
+    }
+
+    @Override
+    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws ServletException, IOException {
+        HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
+        String wxDataSourceName = httpRequest.getHeader("tag");
+        if (wxDataSourceName != null && wxDataSourceName.trim().length() > 0) {
+            log.info("APP寮�鍙戯紝璁剧疆鏁版嵁婧愬悕绉颁负:" + wxDataSourceName);
+            //鎶婄粍缁囧崟浣嶆爣绛句綔涓烘暟鎹簮鍚嶇О
+            DataSourceContext.set(wxDataSourceName);
+        } else {
+            log.info("鐢ㄦ埛鏈�夋嫨鏁版嵁婧�");
+        }
+        filterChain.doFilter(servletRequest, servletResponse);
+    }
+
+    @Override
+    public void destroy() {
+    }
+}
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-app/src/main/java/com/dy/pipIrrApp/config/DataSourceFilterConfiguration.java b/pipIrr-platform/pipIrr-web/pipIrr-web-app/src/main/java/com/dy/pipIrrApp/config/DataSourceFilterConfiguration.java
new file mode 100644
index 0000000..1e6ebd1
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-app/src/main/java/com/dy/pipIrrApp/config/DataSourceFilterConfiguration.java
@@ -0,0 +1,27 @@
+package com.dy.pipIrrApp.config;
+
+import jakarta.servlet.Filter;
+import org.springframework.boot.web.servlet.FilterRegistrationBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * @author ZhuBaoMin
+ * @date 2024-11-29 14:29
+ * @LastEditTime 2024-11-29 14:29
+ * @Description
+ */
+
+@Configuration
+public class DataSourceFilterConfiguration {
+    @Bean
+    public FilterRegistrationBean<? extends Filter> DataSourceFilter() {
+        FilterRegistrationBean<Filter> filterRegistrationBean = new FilterRegistrationBean<>();
+        filterRegistrationBean.setFilter(new DataSourceFilter());
+        filterRegistrationBean.addUrlPatterns("/*");//閰嶇疆杩囨护瑙勫垯
+        filterRegistrationBean.setName("DataSourceFilter");//璁剧疆杩囨护鍣ㄥ悕绉�
+        filterRegistrationBean.setOrder(1);//鎵ц娆″簭
+
+        return filterRegistrationBean;
+    }
+}
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigatePlan/IrrigatePlanCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigatePlan/IrrigatePlanCtrl.java
new file mode 100644
index 0000000..0f22e38
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigatePlan/IrrigatePlanCtrl.java
@@ -0,0 +1,44 @@
+package com.dy.pipIrrIrrigate.irrigatePlan;
+
+import com.dy.common.aop.SsoAop;
+import com.dy.common.webUtil.BaseResponse;
+import com.dy.common.webUtil.BaseResponseUtils;
+import com.dy.pipIrrGlobal.voIr.VoGroupSimple;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+/**
+ * @author ZhuBaoMin
+ * @date 2024-11-28 17:20
+ * @LastEditTime 2024-11-28 17:20
+ * @Description 鐏屾簤璁″垝鎺у埗绫�
+ */
+
+@Slf4j
+@RestController
+@RequestMapping(path = "irrigatePlan")
+@RequiredArgsConstructor
+public class IrrigatePlanCtrl {
+    private final IrrigatePlanSv irrigatePlanSv;
+
+    /**
+     * 鏍规嵁鍐滄埛缂栧彿鑾峰彇杞亴缁勫垪琛�
+     * @return
+     */
+    @GetMapping(path = "/getGroups")
+    @SsoAop()
+    public BaseResponse<List<VoGroupSimple>> getGroups(@RequestParam("clientId") Long clientId) {
+        try {
+            return BaseResponseUtils.buildSuccess(irrigatePlanSv.getGroups(clientId));
+        } catch (Exception e) {
+            log.error("鑾峰彇浠诲姟绫诲瀷寮傚父", e);
+            return BaseResponseUtils.buildException(e.getMessage());
+        }
+    }
+}
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigatePlan/IrrigatePlanSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigatePlan/IrrigatePlanSv.java
new file mode 100644
index 0000000..6350b50
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigatePlan/IrrigatePlanSv.java
@@ -0,0 +1,32 @@
+package com.dy.pipIrrIrrigate.irrigatePlan;
+
+import com.dy.pipIrrGlobal.daoIr.IrGroupClientMapper;
+import com.dy.pipIrrGlobal.voIr.VoGroupSimple;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * @author ZhuBaoMin
+ * @date 2024-11-28 17:20
+ * @LastEditTime 2024-11-28 17:20
+ * @Description 鐏屾簤璁″垝鏈嶅姟绫�
+ */
+
+@Slf4j
+@Service
+public class IrrigatePlanSv {
+    @Autowired
+    private IrGroupClientMapper irGroupClientMapper;
+
+    /**
+     * 鏍规嵁鍐滄埛缂栧彿鑾峰彇杞亴缁勫垪琛�
+     * @param clientId
+     * @return
+     */
+    public List<VoGroupSimple> getGroups(Long clientId) {
+        return irGroupClientMapper.getGroupsByClientId(clientId);
+    }
+}

--
Gitblit v1.8.0