From 351b16d0a3dc194841c2192cacfabf788ecafd5c Mon Sep 17 00:00:00 2001
From: Junjie <540245094@qq.com>
Date: 星期一, 05 八月 2024 08:19:17 +0800
Subject: [PATCH] #

---
 zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/mapper/MatFieldMapper.java |   41 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/mapper/MatFieldMapper.java b/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/mapper/MatFieldMapper.java
index f4f76de..133a840 100644
--- a/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/mapper/MatFieldMapper.java
+++ b/zy-asrs-wms/src/main/java/com/zy/asrs/wms/asrs/mapper/MatFieldMapper.java
@@ -1,12 +1,53 @@
 package com.zy.asrs.wms.asrs.mapper;
 
+import com.zy.asrs.wms.asrs.entity.LocDetlField;
 import com.zy.asrs.wms.asrs.entity.MatField;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.SelectProvider;
 import org.springframework.stereotype.Repository;
+
+import java.util.List;
+import java.util.Map;
 
 @Mapper
 @Repository
 public interface MatFieldMapper extends BaseMapper<MatField> {
 
+    @SelectProvider(type = SqlProvider.class, method = "createViewSql")
+    void createView(@Param("list") List<MatField> list);
+
+
+    @SelectProvider(type = SqlProvider.class, method = "createLocDetlView")
+    void createLocDetlView();
+
+    class SqlProvider {
+        public String createViewSql(Map<String, Object> params) {
+            List<MatField> list = (List<MatField>) params.get("list");
+            StringBuilder sql = new StringBuilder();
+
+            sql.append(" CREATE OR REPLACE VIEW view_man_loc_detl_field AS \n");
+            sql.append(" SELECT detl_id ");
+            for (MatField matField : list) {
+                sql.append(", MAX(CASE WHEN name = '").append(matField.getName()).append("' THEN value END) AS ").append(matField.getName());
+            }
+            sql.append(" FROM man_loc_detl_field ");
+            sql.append(" GROUP BY detl_id ");
+
+            return sql.toString();
+        }
+
+        public String createLocDetlView() {
+            StringBuilder sql = new StringBuilder();
+
+            sql.append(" CREATE OR REPLACE VIEW view_man_loc_detl AS \n");
+            sql.append(" select * from man_loc_detl ld ");
+            sql.append(" left join view_man_loc_detl_field ldf ");
+            sql.append(" on ld.id = ldf.detl_id ");
+
+            return sql.toString();
+        }
+    }
+
 }

--
Gitblit v1.9.1