Kaynağa Gözat

工程現場 接口修改

zhanghao 1 ay önce
ebeveyn
işleme
4d3b9455b0

+ 7 - 0
project-zcustom/src/main/java/com/project/zcustom/controller/backManager/engineering/LargeProjectController.java

@@ -11,6 +11,8 @@ import lombok.RequiredArgsConstructor;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
 import javax.servlet.http.HttpServletResponse;
 import java.util.Arrays;
 import java.util.List;
@@ -71,4 +73,9 @@ public class LargeProjectController extends BaseController {
     public AjaxResult remove(@PathVariable Long[] ids) {
         return toAjax(largeProjectService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
     }
+
+    @PostMapping("/upload")
+    public AjaxResult upload(@RequestParam("file") MultipartFile file) {
+        return toAjax(largeProjectService.upload(file));
+    }
 }

+ 3 - 0
project-zcustom/src/main/java/com/project/zcustom/mapper/unit/LargeProjectMapper.java

@@ -4,6 +4,7 @@ import java.util.List;
 import java.util.Map;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.project.zcustom.domain.addional.LargeHousingLand;
 import com.project.zcustom.domain.addional.LargeProject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Constants;
@@ -77,4 +78,6 @@ public interface LargeProjectMapper extends BaseMapper<LargeProject>
     public int getProjectNumThisWeek(String appOrg);
 
     public List<LargeProject> getProjectNumZ(List<String> appOrg);
+
+    int upload(List<LargeProject> data);
 }

+ 10 - 2
project-zcustom/src/main/java/com/project/zcustom/service/logistics/impl/LargeHousingLandServiceImpl.java

@@ -96,6 +96,14 @@ public class LargeHousingLandServiceImpl extends ServiceImpl<PlatHousingLandMapp
 
         List<LargeHousingLand> data = new ArrayList<>();
 
+        Map<String, Long> mapType = new HashMap<>();
+        mapType.put("办公用房", 0L);
+        mapType.put("周转用房", 1L);
+        mapType.put("生产管理", 2L);
+        mapType.put("教育培训用房", 3L);
+        mapType.put("交流干部住房", 4L);
+        mapType.put("单身公寓/单身宿舍", 5L);
+
         // 跳过表头
         if (rowIterator.hasNext()) {
             rowIterator.next();
@@ -121,8 +129,8 @@ public class LargeHousingLandServiceImpl extends ServiceImpl<PlatHousingLandMapp
                         }
                         break;
                     case 2:
-                        if (cell != null && cell.getCellType() == CellType.NUMERIC) {
-                            a.setType((long) cell.getNumericCellValue());
+                        if (cell != null && cell.getCellType() == CellType.STRING) {
+                            a.setType(mapType.get(cell.getStringCellValue()));
                         }
                         break;
                     case 3:

+ 4 - 0
project-zcustom/src/main/java/com/project/zcustom/service/unit/ILargeProjectService.java

@@ -5,6 +5,8 @@ import com.project.zcustom.domain.addional.LargeProject;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.project.common.core.domain.search.PageParamVo;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import org.springframework.web.multipart.MultipartFile;
+
 import java.util.List;
 import java.util.Map;
 
@@ -101,4 +103,6 @@ public interface ILargeProjectService extends IService<LargeProject> {
     public int getProjectNumThisWeek(String appOrg);
 
     public Map<String, Object> getProjectNumZ();
+
+    int upload(MultipartFile file);
 }

+ 117 - 7
project-zcustom/src/main/java/com/project/zcustom/service/unit/impl/LargeProjectServiceImpl.java

@@ -1,18 +1,24 @@
 package com.project.zcustom.service.unit.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.project.common.core.domain.search.PageParamVo;
+import com.project.common.utils.StringUtils;
 import com.project.zcustom.domain.addional.LargeProject;
 import com.project.zcustom.mapper.unit.LargeProjectMapper;
 import com.project.zcustom.service.unit.ILargeProjectService;
-import com.project.common.core.domain.search.PageParamVo;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.project.common.utils.StringUtils;
+import org.springframework.web.multipart.MultipartFile;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.math.BigDecimal;
 import java.util.*;
 
 /**
@@ -217,4 +223,108 @@ public class LargeProjectServiceImpl extends ServiceImpl<LargeProjectMapper, Lar
         }
         return map;
     }
+
+    public int upload(MultipartFile file){
+        try {
+            List<LargeProject> data = parseExcel(file.getInputStream());
+            largeProjectMapper.upload(data);
+            return 1;
+        } catch (Exception e) {
+            e.printStackTrace();
+            return 0;
+        }
+    }
+
+    // 解析 Excel 文件
+    private List<LargeProject> parseExcel(InputStream inputStream) throws IOException {
+        Workbook workbook = new XSSFWorkbook(inputStream);
+        Sheet sheet = workbook.getSheetAt(0); // 获取第一个表单
+        Iterator<Row> rowIterator = sheet.iterator();
+
+        List<LargeProject> data = new ArrayList<>();
+
+        // 跳过表头
+        if (rowIterator.hasNext()) {
+            rowIterator.next();
+        }
+
+        Map<String, String> mapType = new HashMap<>();
+        mapType.put("在建", "0");
+        mapType.put("施工", "2");
+        Map<String, Long> mapSubdivision = new HashMap<>();
+        mapSubdivision.put("可研评审", 1L);
+        mapSubdivision.put("初设评审", 2L);
+        mapSubdivision.put("政府立项备案", 3L);
+        mapSubdivision.put("土地手续", 4L);
+        mapSubdivision.put("用地规划", 5L);
+        mapSubdivision.put("工程规划", 6L);
+        mapSubdivision.put("设计招标", 7L);
+        mapSubdivision.put("施工招标", 8L);
+        mapSubdivision.put("监理招标", 9L);
+        mapSubdivision.put("施工许可", 10L);
+        mapSubdivision.put("基础施工", 11L);
+        mapSubdivision.put("主体工程", 12L);
+        mapSubdivision.put("室内外装修", 13L);
+        mapSubdivision.put("室外工程", 14L);
+
+        // 遍历每一行
+        while (rowIterator.hasNext()) {
+            Row row = rowIterator.next();
+            LargeProject a = new LargeProject();
+
+            for (int i = 0; i < row.getPhysicalNumberOfCells(); i++) {
+                Cell cell = row.getCell(i);
+
+                switch (i) {
+                    case 0:
+                        if (cell != null && cell.getCellType() == CellType.STRING) {
+                            a.setProjectName(cell.getStringCellValue());
+                        }
+                        break;
+                    case 1:
+                        if (cell != null && cell.getCellType() == CellType.STRING) {
+                            a.setAppOrg(cell.getStringCellValue());
+                        }
+                        break;
+                    case 2:
+                        if (cell != null && cell.getCellType() == CellType.STRING) {
+                            a.setType(mapType.get(cell.getStringCellValue()));
+                        }
+                        break;
+                    case 3:
+                        if (cell != null && cell.getCellType() == CellType.STRING) {
+                            a.setSubdivision(mapSubdivision.get(cell.getStringCellValue()));
+                        }
+                        break;
+                    case 4:
+                        if (cell != null && cell.getCellType() == CellType.NUMERIC) {
+                            a.setAbscissa(BigDecimal.valueOf(cell.getNumericCellValue()));
+                        }
+                        break;
+                    case 5:
+                        if (cell != null && cell.getCellType() == CellType.NUMERIC) {
+                            a.setOrdinate(BigDecimal.valueOf(cell.getNumericCellValue()));
+                        }
+                        break;
+                    case 6:
+                        if (cell != null && cell.getCellType() == CellType.STRING) {
+                            a.setSupervisionUnit(cell.getStringCellValue());
+                        }
+                        break;
+                    case 7:
+                        if (cell != null && cell.getCellType() == CellType.STRING) {
+                            a.setConstructionUnit(cell.getStringCellValue());
+                        }
+                        break;
+                    default:
+                        break;
+                }
+            }
+
+            data.add(a);
+        }
+
+        workbook.close();
+        return data;
+    }
 }

+ 27 - 0
project-zcustom/src/main/resources/mapper/zcustom/unit/LargeProjectMapper.xml

@@ -195,4 +195,31 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             a.del_flag = '0'
           AND b.del_flag = '0'
     </select>
+
+    <insert id="upload" parameterType="com.project.zcustom.domain.addional.LargeProject">
+        insert into large_plat_housing_land (supervision_unit,
+        construction_unit,
+        ordinate,
+        abscissa,
+        project_name,
+        app_org,
+        type,
+        subdivision,
+        del_flag,
+        create_time)
+        values
+        <foreach collection="list" item="item" separator="," close=";">
+            <trim prefix="(" suffix=")" suffixOverrides=",">
+                #{item.supervisionUnit},
+                #{item.constructionUnit},
+                #{item.ordinate},
+                #{item.abscissa},
+                #{item.projectName},
+                #{item.appOrg},
+                #{item.type},
+                #{item.subdivision},
+                '0', sysdate()
+            </trim>
+        </foreach>
+    </insert>
 </mapper>